DXR is a code search and navigation tool aimed at making sense of large projects. It supports full-text and regex searches as well as structural queries.

Mercurial (b6d82b1a6b02)

VCS Links

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199
<html>
<head>
  <title>Test subresources prompts (Bug 625187 and bug 1230462)</title>
  <script type="text/javascript" src="/MochiKit/MochiKit.js"></script>
  <script src="/tests/SimpleTest/SimpleTest.js"></script>
  <script src="/tests/SimpleTest/EventUtils.js"></script>
  <script type="text/javascript" src="prompt_common.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css">
<!--
   - Any copyright is dedicated to the Public Domain.
   - http://creativecommons.org/publicdomain/zero/1.0/
   -
   - Contributor(s):
   -   Mihai Sucan <mihai.sucan@gmail.com>
   -->
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=625187">Mozilla Bug 625187</a>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1230462">Mozilla Bug 1230462</a>

<p><button onclick="alert('hello world')">Button</button></p>

<iframe id="iframe_diff_origin" src="http://example.com/tests/toolkit/components/prompts/test/bug625187_iframe.html"></iframe>

<iframe id="iframe_same_origin" src="bug625187_iframe.html"></iframe>

<iframe id="iframe_prompt"></iframe>

<pre id="test"></pre>

<script class="testbody" type="text/javascript">
var iframe1Loaded = onloadPromiseFor("iframe_diff_origin");
var iframe2Loaded = onloadPromiseFor("iframe_same_origin");
var iframe_prompt = document.getElementById("iframe_prompt");

add_task(async function runTest() {
  // This test depends on tab modal prompts being enabled.
  if (!isTabModal) {
    todo(false, "Test disabled when tab modal prompts are not enabled.");
    return;
  }

  info("Ensuring iframe1 has loaded...");
  await iframe1Loaded;
  info("Ensuring iframe2 has loaded...");
  await iframe2Loaded;
  let state, action;

  state = {
    msg: "hello world",
    iconClass: "alert-icon",
    titleHidden: true,
    textHidden: true,
    passHidden: true,
    checkHidden: true,
    textValue: "",
    passValue: "",
    checkMsg: "",
    checked: false,
    focused: "button0",
    defButton: "button0",
  };
  action = {
    buttonClick: "ok",
  };

  let promptDone = handlePrompt(state, action);

  var button = document.querySelector("button");
  dispatchMouseEvent(button, "click");

  await promptDone;


  // mostly reusing same state/action
  state.titleHidden = false;
  state.msg = "hello world 2";
  promptDone = handlePrompt(state, action);

  var iframe = document.getElementById("iframe_diff_origin");
  button = SpecialPowers.wrap(iframe.contentWindow).document.getElementById("btn1");
  dispatchMouseEvent(button, "click");

  await promptDone;


  // mostly reusing same state/action
  state.titleHidden = true;
  state.msg = "hello world 2";
  promptDone = handlePrompt(state, action);

  iframe = document.getElementById("iframe_same_origin");
  button = iframe.contentWindow.document.getElementById("btn1");
  dispatchMouseEvent(button, "click");

  await promptDone;


  // mostly reusing same state/action
  state.msg = "hello world 3";
  promptDone = handlePrompt(state, action);

  button = iframe.contentWindow.document.getElementById("btn2");
  dispatchMouseEvent(button, "click");

  await promptDone;
});

add_task(async function runTestAuth() {
  // Following tests chack prompt message for a cross-origin and not
  // cross-origin subresources load

  // Force parent to not look for tab-modal prompts, as they're not
  // used for auth prompts.
  isTabModal = false;
  let state, action;

  state = {
    msg: "http://mochi.test:8888 is requesting your username " +
         "and password. The site says: “mochitest”",
    title: "Authentication Required",
    textValue: "",
    passValue: "",
    iconClass: "authentication-icon question-icon",
    titleHidden: true,
    textHidden: false,
    passHidden: false,
    checkHidden: true,
    checkMsg: "",
    checked: false,
    focused: "textField",
    defButton: "button0",
  };

  action = {
    buttonClick: "ok",
    setCheckbox: false,
    textField: "mochiuser1",
    passField: "mochipass1",
  };

  let promptDone = handlePrompt(state, action);

  var iframe3Loaded = onloadPromiseFor("iframe_prompt");
  iframe_prompt.src = "authenticate.sjs?user=mochiuser1&pass=mochipass1";
  await promptDone;
  await iframe3Loaded;
  checkEchoedAuthInfo({user: "mochiuser1", pass: "mochipass1"},
                      iframe_prompt.contentDocument);

  // Cross-origin subresourse test.

  // Force parent to not look for tab-modal prompts, as they're not used for auth prompts.
  isTabModal = false;
  state = {
    msg: "http://example.com is requesting your username and password. " +
         "WARNING: Your password will not be sent to the website you are currently visiting!",
    title: "Authentication Required",
    textValue: "",
    passValue: "",
    iconClass: "authentication-icon question-icon",
    titleHidden: true,
    textHidden: false,
    passHidden: false,
    checkHidden: true,
    checkMsg: "",
    checked: false,
    focused: "textField",
    defButton: "button0",
  };

  action = {
    buttonClick: "ok",
    setCheckbox: false,
    textField: "mochiuser2",
    passField: "mochipass2",
  };

  promptDone = handlePrompt(state, action);

  iframe3Loaded = onloadPromiseFor("iframe_prompt");
  iframe_prompt.src = "http://example.com/tests/toolkit/components/prompts/test/authenticate.sjs?user=mochiuser2&pass=mochipass2&realm=mochitest";
  await promptDone;
  await iframe3Loaded;
  checkEchoedAuthInfo({user: "mochiuser2", pass: "mochipass2"},
                      SpecialPowers.wrap(iframe_prompt.contentWindow).document);
});

function dispatchMouseEvent(target, type) {
  var win = SpecialPowers.unwrap(target.ownerDocument.defaultView);
  var e = document.createEvent("MouseEvent");
  e.initEvent(type, false, false, win, 0, 1, 1, 1, 1,
              false, false, false, false, 0, null);
  var utils = SpecialPowers.getDOMWindowUtils(win);
  utils.dispatchDOMEventViaPresShell(SpecialPowers.unwrap(target), e);
}
</script>
</body>
</html>