summaryrefslogtreecommitdiffstats
path: root/browser/components/urlbar/tests/browser/browser_hashChangeProxyState.js
blob: d0e236fe7ef16d960017df46ac9fe124489cd697 (plain)
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
/* Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

/**
 * Check that navigating through both the URL bar and using in-page hash- or ref-
 * based links and back or forward navigation updates the URL bar and identity block correctly.
 */
add_task(async function () {
  await SpecialPowers.pushPrefEnv({
    set: [["browser.navigation.requireUserInteraction", false]],
  });
  let baseURL = `${TEST_BASE_URL}dummy_page.html`;
  let url = baseURL + "#foo";
  await BrowserTestUtils.withNewTab(
    { gBrowser, url },
    async function (browser) {
      let identityBox = document.getElementById("identity-box");
      let expectedURL = url;

      let verifyURLBarState = testType => {
        is(
          gURLBar.value,
          expectedURL,
          "URL bar visible value should be correct " + testType
        );
        is(
          gURLBar.untrimmedValue,
          expectedURL,
          "URL bar value should be correct " + testType
        );
        ok(
          identityBox.classList.contains("verifiedDomain"),
          "Identity box should know we're doing SSL " + testType
        );
        is(
          gURLBar.getAttribute("pageproxystate"),
          "valid",
          "URL bar is in valid page proxy state"
        );
      };

      verifyURLBarState("at the beginning");

      let locationChangePromise;
      let resolveLocationChangePromise;
      let expectURL = urlTemp => {
        expectedURL = urlTemp;
        locationChangePromise = new Promise(
          r => (resolveLocationChangePromise = r)
        );
      };
      let wpl = {
        onLocationChange(unused, unused2, location) {
          is(location.spec, expectedURL, "Got the expected URL");
          resolveLocationChangePromise();
        },
      };
      gBrowser.addProgressListener(wpl);

      expectURL(baseURL + "#foo");
      gURLBar.select();
      EventUtils.sendKey("return");

      await locationChangePromise;
      verifyURLBarState("after hitting enter on the same URL a second time");

      expectURL(baseURL + "#bar");
      gURLBar.value = expectedURL;
      gURLBar.select();
      EventUtils.sendKey("return");

      await locationChangePromise;
      verifyURLBarState("after a URL bar hash navigation");

      expectURL(baseURL + "#foo");
      await SpecialPowers.spawn(browser, [], function () {
        let a = content.document.createElement("a");
        a.href = "#foo";
        a.textContent = "Foo Link";
        content.document.body.appendChild(a);
        a.click();
      });

      await locationChangePromise;
      verifyURLBarState("after a page link hash navigation");

      expectURL(baseURL + "#bar");
      gBrowser.goBack();

      await locationChangePromise;
      verifyURLBarState("after going back");

      expectURL(baseURL + "#foo");
      gBrowser.goForward();

      await locationChangePromise;
      verifyURLBarState("after going forward");

      expectURL(baseURL + "#foo");
      gURLBar.select();
      EventUtils.sendKey("return");

      await locationChangePromise;
      verifyURLBarState("after hitting enter on the same URL");

      gBrowser.removeProgressListener(wpl);
    }
  );
});

/**
 * Check that initial secure loads that swap remoteness
 * get the correct page icon when finished.
 */
add_task(async function () {
  // Ensure there's no preloaded newtab browser, since that'll not fire a load event.
  NewTabPagePreloading.removePreloadedBrowser(window);
  let tab = await BrowserTestUtils.openNewForegroundTab(
    gBrowser,
    "about:newtab"
  );
  let url = `${TEST_BASE_URL}dummy_page.html#foo`;
  gURLBar.value = url;
  gURLBar.select();
  EventUtils.sendKey("return");
  await BrowserTestUtils.browserLoaded(tab.linkedBrowser);

  is(
    gURLBar.value,
    url,
    "URL bar visible value should be correct when the page loads from about:newtab"
  );
  is(
    gURLBar.untrimmedValue,
    url,
    "URL bar value should be correct when the page loads from about:newtab"
  );
  let identityBox = document.getElementById("identity-box");
  ok(
    identityBox.classList.contains("verifiedDomain"),
    "Identity box should know we're doing SSL when the page loads from about:newtab"
  );
  is(
    gURLBar.getAttribute("pageproxystate"),
    "valid",
    "URL bar is in valid page proxy state when SSL page with hash loads from about:newtab"
  );
  BrowserTestUtils.removeTab(tab);
});