diff options
author | finnur@chromium.org <finnur@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-31 04:24:17 +0000 |
---|---|---|
committer | finnur@chromium.org <finnur@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-31 04:24:17 +0000 |
commit | 711abaeaaec2bb552d9fe161200778f449fd2da0 (patch) | |
tree | 043dec5763dbb378464f0a9d813b08892c62a40a /chrome/test | |
parent | 2f7c97fec82e0a4bebdf0fced4cf9db7ac574497 (diff) | |
download | chromium_src-711abaeaaec2bb552d9fe161200778f449fd2da0.zip chromium_src-711abaeaaec2bb552d9fe161200778f449fd2da0.tar.gz chromium_src-711abaeaaec2bb552d9fe161200778f449fd2da0.tar.bz2 |
Adding API tests for getViews and infobars.
Also fixing a bug where the wrong window id was returned
back after creating the infobar, and changing html path param
when calling show() from htlpPath to path as requrested by aa.
TEST=See chrome_tests.gypi
BUG=26463
Review URL: http://codereview.chromium.org/1561003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@43176 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/test')
11 files changed, 164 insertions, 0 deletions
diff --git a/chrome/test/data/extensions/api_test/get_views/infobar.html b/chrome/test/data/extensions/api_test/get_views/infobar.html new file mode 100644 index 0000000..e28f8e3 --- /dev/null +++ b/chrome/test/data/extensions/api_test/get_views/infobar.html @@ -0,0 +1,4 @@ +<script> + var background_page = chrome.extension.getBackgroundPage(); + background_page.infobarCallback(); +</script>
\ No newline at end of file diff --git a/chrome/test/data/extensions/api_test/get_views/manifest.json b/chrome/test/data/extensions/api_test/get_views/manifest.json new file mode 100644 index 0000000..18f5d00 --- /dev/null +++ b/chrome/test/data/extensions/api_test/get_views/manifest.json @@ -0,0 +1,7 @@ +{ + "name": "chrome.extension.getViews", + "version": "0.1", + "description": "end-to-end browser test for chrome.extension.getViews API", + "background_page": "test.html", + "permissions": ["experimental", "tabs"] +} diff --git a/chrome/test/data/extensions/api_test/get_views/options.html b/chrome/test/data/extensions/api_test/get_views/options.html new file mode 100644 index 0000000..4fbc49a --- /dev/null +++ b/chrome/test/data/extensions/api_test/get_views/options.html @@ -0,0 +1,6 @@ +<script> + var background_page = chrome.extension.getBackgroundPage(); + background_page.optionsPageCallback(); +</script> + +Options page.
\ No newline at end of file diff --git a/chrome/test/data/extensions/api_test/get_views/test.html b/chrome/test/data/extensions/api_test/get_views/test.html new file mode 100644 index 0000000..46f4d74 --- /dev/null +++ b/chrome/test/data/extensions/api_test/get_views/test.html @@ -0,0 +1 @@ +<script src="test.js"></script> diff --git a/chrome/test/data/extensions/api_test/get_views/test.js b/chrome/test/data/extensions/api_test/get_views/test.js new file mode 100644 index 0000000..4c8e90e --- /dev/null +++ b/chrome/test/data/extensions/api_test/get_views/test.js @@ -0,0 +1,51 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// API test for chrome.extension.getViews. +// browser_tests.exe --gtest_filter=ExtensionApiTest.GetViews + +const assertEq = chrome.test.assertEq; +const assertTrue = chrome.test.assertTrue; + +// This function is called by the infobar during the test run. +function infobarCallback() { + // We have now added an infobar so the total count goes up one. + assertEq(2, chrome.extension.getViews().length); + assertEq(1, chrome.extension.getViews({"type": "infobar"}).length); + + // Now try the same, but specify the windowId. + chrome.windows.getCurrent(function(window) { + assertEq(1, chrome.extension.getViews( + {"type": "infobar", "windowId": window.id}).length); + chrome.tabs.create({"url": chrome.extension.getURL("options.html")}); + }); +} + +function optionsPageCallback() { + assertEq(3, chrome.extension.getViews().length); + assertEq(1, chrome.extension.getViews( + {"type": "infobar", "windowId": window.id}).length); + assertEq(1, chrome.extension.getViews( + {"type": "tab", "windowId": window.id}).length); + chrome.test.notifyPass(); +} + +var tests = [ + function getViews() { + assertTrue(typeof(chrome.extension.getBackgroundPage()) != "undefined"); + assertEq(1, chrome.extension.getViews().length); + assertEq(0, chrome.extension.getViews({"type": "tab"}).length); + assertEq(0, chrome.extension.getViews({"type": "infobar"}).length); + assertEq(0, chrome.extension.getViews({"type": "notification"}).length); + + // Show an infobar. + chrome.experimental.infobars.show({"path": "infobar.html"}, + function(window) { + assertTrue(window.id > 0); + // The infobar will call back to us through infobarCallback (above). + }); + } +]; + +chrome.test.runTests(tests); diff --git a/chrome/test/data/extensions/api_test/infobars/icon.png b/chrome/test/data/extensions/api_test/infobars/icon.png Binary files differnew file mode 100644 index 0000000..9a79a46 --- /dev/null +++ b/chrome/test/data/extensions/api_test/infobars/icon.png diff --git a/chrome/test/data/extensions/api_test/infobars/infobarA.html b/chrome/test/data/extensions/api_test/infobars/infobarA.html new file mode 100644 index 0000000..e8d7c43 --- /dev/null +++ b/chrome/test/data/extensions/api_test/infobars/infobarA.html @@ -0,0 +1,6 @@ +<script> + var background_page = chrome.extension.getBackgroundPage(); + background_page.infobarCallbackA(); +</script> + +Infobar A
\ No newline at end of file diff --git a/chrome/test/data/extensions/api_test/infobars/infobarB.html b/chrome/test/data/extensions/api_test/infobars/infobarB.html new file mode 100644 index 0000000..77c093c --- /dev/null +++ b/chrome/test/data/extensions/api_test/infobars/infobarB.html @@ -0,0 +1,6 @@ +<script> + var background_page = chrome.extension.getBackgroundPage(); + background_page.infobarCallbackB(); +</script> + +Infobar B diff --git a/chrome/test/data/extensions/api_test/infobars/manifest.json b/chrome/test/data/extensions/api_test/infobars/manifest.json new file mode 100644 index 0000000..634af88 --- /dev/null +++ b/chrome/test/data/extensions/api_test/infobars/manifest.json @@ -0,0 +1,8 @@ +{ + "name": "chrome.extension.infobars", + "version": "0.1", + "description": "end-to-end browser test for chrome.extension.infobars API", + "background_page": "test.html", + "icons": { "16": "icon.png" }, + "permissions": ["experimental", "tabs"] +} diff --git a/chrome/test/data/extensions/api_test/infobars/test.html b/chrome/test/data/extensions/api_test/infobars/test.html new file mode 100644 index 0000000..46f4d74 --- /dev/null +++ b/chrome/test/data/extensions/api_test/infobars/test.html @@ -0,0 +1 @@ +<script src="test.js"></script> diff --git a/chrome/test/data/extensions/api_test/infobars/test.js b/chrome/test/data/extensions/api_test/infobars/test.js new file mode 100644 index 0000000..68d59a3 --- /dev/null +++ b/chrome/test/data/extensions/api_test/infobars/test.js @@ -0,0 +1,74 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// API test for chrome.extension.infobars. +// browser_tests.exe --gtest_filter=ExtensionApiTest.Infobars + +const assertEq = chrome.test.assertEq; +const assertTrue = chrome.test.assertTrue; + +var windowA = 0; +var windowB = 0; +var tabA = 0; + +var tests = [ + function createInfobars() { + // Only background page should be active at the start. + assertEq(1, chrome.extension.getViews().length); + + // Get the current tab and window (window A), then create a new + // one (window B). + chrome.tabs.getSelected(null, function(tab) { + tabA = tab.id; + windowA = tab.windowId; + console.log('tabid: ' + tabA + ' windowA: ' + windowA); + + chrome.windows.create({"url": "about:blank"}, function(window) { + windowB = window.id; + console.log('windowB: ' + windowB); + + // Show infobarA in window A (tab A) (and specify no callback). + chrome.experimental.infobars.show({"path": "infobarA.html", + "tabId": tabA}); + // Flow continues in infobarCallbackA. + }); + }); + } +]; + +function infobarCallbackA() { + // We have now added an infobar so the total count goes up one. + assertEq(2, chrome.extension.getViews().length); + assertEq(1, chrome.extension.getViews({"type": "infobar"}).length); + // Window A should have 1 infobar. + assertEq(1, chrome.extension.getViews({"type": "infobar", + "windowId": windowA}).length); + // Window B should have no infobars. + assertEq(0, chrome.extension.getViews({"type": "infobar", + "windowId": windowB}).length); + + // Show infobarB in (current) window B (with callback). + chrome.experimental.infobars.show({"path": "infobarB.html"}, + function(window) { + assertTrue(window.id == windowB); + // This infobar will call back to us through infobarCallbackB (below). + }); +} + +function infobarCallbackB() { + // We have now added an infobar so the total count goes up one. + assertEq(3, chrome.extension.getViews().length); + assertEq(2, chrome.extension.getViews({"type": "infobar"}).length); + + // Window A should have 1 infobar. + assertEq(1, chrome.extension.getViews({"type": "infobar", + "windowId": windowA}).length); + // Window B should have 1 infobar. + assertEq(1, chrome.extension.getViews({"type": "infobar", + "windowId": windowB}).length); + + chrome.test.notifyPass(); +} + +chrome.test.runTests(tests); |