summaryrefslogtreecommitdiffstats
path: root/toolkit/components/satchel/test/browser/browser_privbrowsing_perwindowpb.js
blob: 982480648f1319be4c244af5547f82d9c99923fa (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
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

var FormHistory = (Components.utils.import("resource://gre/modules/FormHistory.jsm", {})).FormHistory;

/** Test for Bug 472396 **/
add_task(function* test() {
  // initialization
  let windowsToClose = [];
  let testURI =
    "http://example.com/tests/toolkit/components/satchel/test/subtst_privbrowsing.html";

  function* doTest(aShouldValueExist, aWindow) {
    let browser = aWindow.gBrowser.selectedBrowser;
    BrowserTestUtils.loadURI(browser, testURI);
    yield BrowserTestUtils.browserLoaded(browser);

    // Wait for the page to reload itself.
    yield BrowserTestUtils.browserLoaded(browser);

    let count = 0;
    let doneCounting = {};
    doneCounting.promise = new Promise(resolve => doneCounting.resolve = resolve);
    FormHistory.count({ fieldname: "field", value: "value" },
                      {
                        handleResult(result) {
                          count = result;
                        },
                        handleError(error) {
                          do_throw("Error occurred searching form history: " + error);
                        },
                        handleCompletion(num) {
                          if (aShouldValueExist) {
                            is(count, 1, "In non-PB mode, we add a single entry");
                          } else {
                            is(count, 0, "In PB mode, we don't add any entries");
                          }

                          doneCounting.resolve();
                        }
                      });
    yield doneCounting.promise;
  }

  function testOnWindow(aOptions, aCallback) {
    return BrowserTestUtils.openNewBrowserWindow(aOptions)
                           .then(win => { windowsToClose.push(win); return win; });
  }


  yield testOnWindow({private: true}).then((aWin) => {
    return Task.spawn(doTest(false, aWin));
  });

  // Test when not on private mode after visiting a site on private
  // mode. The form history should not exist.
  yield testOnWindow({}).then((aWin) => {
    return Task.spawn(doTest(true, aWin));
  });

  yield Promise.all(windowsToClose.map(win => BrowserTestUtils.closeWindow(win)));
});