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

Unified Diff: chrome/test/data/extensions/api_test/runtime/open_options_page/test.js

Issue 1005673002: Make UI or API driven extension options navigations refocus any existing options page. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Test Created 5 years, 9 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/runtime/open_options_page/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/runtime/open_options_page/test.js
diff --git a/chrome/test/data/extensions/api_test/runtime/open_options_page/test.js b/chrome/test/data/extensions/api_test/runtime/open_options_page/test.js
index 471da1231649a5f03f665b0a3022cbd6ac4318d3..049167a8525b59907ed3f308a2d459d7db4fe34f 100644
--- a/chrome/test/data/extensions/api_test/runtime/open_options_page/test.js
+++ b/chrome/test/data/extensions/api_test/runtime/open_options_page/test.js
@@ -5,14 +5,64 @@
// browser_tests --gtest_filter=ExtensionApiTest.OpenOptionsPage
var assertEq = chrome.test.assertEq;
+var assertTrue = chrome.test.assertTrue;
+var listenOnce = chrome.test.listenOnce;
+var pass = chrome.test.callbackPass;
-function test() {
- chrome.test.listenOnce(chrome.runtime.onMessage, function(m, sender) {
- assertEq('success', m);
- assertEq(chrome.runtime.id, sender.id);
- assertEq(chrome.runtime.getURL('options.html'), sender.url);
+var optionsTabUrl = 'chrome://extensions/?options=' + chrome.runtime.id;
+
+// Finds the Tab for an options page, or null if no options page is open.
+// Asserts that there is at most 1 options page open.
+// Result is passed to |callback|.
+function findOptionsTab(callback) {
+ chrome.tabs.query({url: optionsTabUrl}, pass(function(tabs) {
+ assertTrue(tabs.length <= 1);
+ callback(tabs.length == 0 ? null : tabs[0]);
+ }));
+}
+
+// Tests opening a new options page.
+function testNewOptionsPage() {
+ findOptionsTab(function(tab) {
+ assertEq(null, tab);
+ listenOnce(chrome.runtime.onMessage, function(m, sender) {
+ assertEq('success', m);
+ assertEq(chrome.runtime.id, sender.id);
+ assertEq(chrome.runtime.getURL('options.html'), sender.url);
+ });
+ chrome.runtime.openOptionsPage();
+ });
+}
+
+// Gets the active tab, or null if no tab is active. Asserts that there is at
+// most 1 active tab. Result is passed to |callback|.
+function getActiveTab(callback) {
+ chrome.tabs.query({active: true}, pass(function(tabs) {
+ assertTrue(tabs.length <= 1);
+ callback(tabs.length == 0 ? null : tabs[0]);
+ }));
+}
+
+// Tests refocusing an existing page.
+function testRefocusExistingOptionsPage() {
+ var testUrl = 'chrome://chrome/';
+
+ // There will already be an options page open from the last test. Find it,
+ // focus away from it, then make sure openOptionsPage() refocuses it.
+ findOptionsTab(function(optionsTab) {
+ assertTrue(optionsTab != null);
+ chrome.tabs.create({url: testUrl}, pass(function(tab) {
+ // Make sure the new tab is active.
+ getActiveTab(function(activeTab) {
+ assertEq(testUrl, activeTab.url);
+ // Open options page should refocus it.
+ chrome.runtime.openOptionsPage();
+ getActiveTab(function(activeTab) {
+ assertEq(optionsTabUrl, activeTab.url);
+ });
+ });
+ }));
});
- chrome.runtime.openOptionsPage();
}
-chrome.test.runTests([test]);
+chrome.test.runTests([testNewOptionsPage, testRefocusExistingOptionsPage]);
« no previous file with comments | « chrome/test/data/extensions/api_test/runtime/open_options_page/manifest.json ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698