"use strict";

const test = require("sdk/test");
const windows = require("sdk/windows").browserWindows;
const httpd = require("./lib/httpd");
const {doGetFile, getTestActivityStream} = require("./lib/utils");

const PORT = 8199;

exports["test activity stream doesn't load in private windows"] = function*(assert) {
  let path = "/dummy-activitystreams.html";
  let url = `http://localhost:${PORT}${path}`;
  let srv = httpd.startServerAsync(PORT, null, doGetFile("test/resources"));
  let app = getTestActivityStream({pageURL: url});

  // Open a private browsing window to test with.
  let window = yield new Promise(resolve => windows.open({
    url: "about:privatebrowsing",
    isPrivate: true,
    onOpen: window => {
      resolve(window);
    }
  }));

  // Try opening all the app URLs. It should open about:privatebrowsing instead.
  for (let appURL of app.appURLs) {
    yield new Promise(resolve => {
      window.tabs.open({
        url: appURL,
        onReady: tab => {
          assert.equal(tab.url, "about:privatebrowsing");
          tab.close(resolve);
        }
      });
    });
  }

  // Cleanup
  yield new Promise(resolve => window.close(resolve));

  app.unload();
  yield new Promise(resolve => {
    srv.stop(resolve);
  });
};

test.run(exports);

@@ -992,28 +992,153 @@
     
-assert.equal
+// onReady may fire more than once. The important thing is that we end up%0A          // on about:privatebrowsing at the end.%0A          if 
 (tab.url
 , %22a
@@ -1133,17 +1133,20 @@
 (tab.url
-,
+ ===
  %22about:
@@ -1162,17 +1162,18 @@
 owsing%22)
-;
+ %7B
 %0A       
@@ -1175,16 +1175,18 @@
         
+  
 tab.clos
@@ -1197,16 +1197,28 @@
 solve);%0A
+          %7D%0A
         

fix (tests): #1045 fix for private browsing test