Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(8220)

Unified Diff: chrome/test/data/extensions/api_test/app_background_page/two_pages/test.html

Issue 8116015: Now closes existing background contents if app opens a new one. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed presubmit error (added license header to js file) Created 9 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/test/data/extensions/api_test/app_background_page/two_pages/manifest.json ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/test/data/extensions/api_test/app_background_page/two_pages/test.html
diff --git a/chrome/test/data/extensions/api_test/app_background_page/two_pages/test.html b/chrome/test/data/extensions/api_test/app_background_page/two_pages/test.html
new file mode 100644
index 0000000000000000000000000000000000000000..b88829a6ef29e10913a918b51b38ae8efff27a8b
--- /dev/null
+++ b/chrome/test/data/extensions/api_test/app_background_page/two_pages/test.html
@@ -0,0 +1,95 @@
+<script>
+// This test runs through an expected use of a live background page:
+// - A live (web-extent) web page is loaded (a.html), which opens the background
+// page.
+// - The first page is closed and a second live web page is loaded (c.html),
+// which uses a different name. This second page also checks a counter which
+// should have a value consistent with being called once.
+// - We then reopen the first page. This first page also checks a counter
+// which should have a value consistent with the page being newly opened.
+// - The background page closes itself.
+
+var pageA;
+var pageC;
+var step = 0;
+
+var pagePrefix =
+ 'http://a.com:PORT/files/extensions/api_test/app_background_page/common';
+
+// Dispatch "tunneled" functions from the live web pages to this testing page.
+chrome.extension.onRequest.addListener(function(request) {
+ window[request.name](request.args);
+});
+
+// At no point should a window be created that contains the background page
+// (bg.html).
+chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) {
+ if (tab.url.match("bg\.html$")) {
+ chrome.test.notifyFail("popup opened instead of background page");
+ }
+});
+
+// Start the test by opening the first page in the app.
+window.onload = function() {
+ // We wait for window.onload before getting the test config. If the
+ // config is requested before onload, then sometimes onload has already
+ // fired by the time chrome.test.getConfig()'s callback runs.
+ chrome.test.getConfig(function(config) {
+ var a_url =
+ pagePrefix.replace(/PORT/, config.testServer.port) + '/a.html';
+ chrome.tabs.create({ 'url': a_url }, function(tab) {
+ pageA = tab;
+ });
+ });
+}
+
+// Background page opened.
+function onBackgroundPageLoaded() {
+ // There are 3 steps to this test:
+ // #1: page A just opened and opened its background page, so we close pageA
+ // and open pageC.
+ // #2: page C just opened and opened its background page, so we close pageC
+ // and reopen pageA.
+ // #3: page A opened again and opened its background page, so we're done.
+ if (step == 0) {
+ // Close A, open C.
+ chrome.tabs.remove(pageA.id, function() {
+ chrome.test.getConfig(function(config) {
+ var c_url =
+ pagePrefix.replace(/PORT/, config.testServer.port) + '/c.html';
+ chrome.tabs.create({ url: c_url }, function(tab) {
+ pageC = tab;
+ });
+ });
+ });
+ } else if (step == 1) {
+ // Close C, re-open A
+ chrome.tabs.remove(pageC.id, function() {
+ chrome.test.getConfig(function(config) {
+ var a_url =
+ pagePrefix.replace(/PORT/, config.testServer.port) + '/a.html';
+ chrome.tabs.create({ url: a_url }, function(tab) {
+ pageA = tab;
+ });
+ });
+ });
+ } else if (step == 2) {
+ chrome.test.notifyPass();
+ } else {
+ chrome.test.notifyFail("onBackgroundPageLoaded() called too many times");
+ }
+ step++;
+}
+
+// Background page responded to pageC.
+function onBackgroundPageResponded() {
+ chrome.test.notifyFail("onBackgroundPageResponded called unexpectedly");
+}
+
+// The background counter check found an unexpected value (most likely caused
+// by an unwanted navigation.
+function onCounterError() {
+ chrome.test.notifyFail("checkCounter found an unexpected value");
+}
+
+</script>
« no previous file with comments | « chrome/test/data/extensions/api_test/app_background_page/two_pages/manifest.json ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698