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

Side by Side 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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // browser_tests --gtest_filter=ExtensionApiTest.OpenOptionsPage 5 // browser_tests --gtest_filter=ExtensionApiTest.OpenOptionsPage
6 6
7 var assertEq = chrome.test.assertEq; 7 var assertEq = chrome.test.assertEq;
8 var assertTrue = chrome.test.assertTrue;
9 var listenOnce = chrome.test.listenOnce;
10 var pass = chrome.test.callbackPass;
8 11
9 function test() { 12 var optionsTabUrl = 'chrome://extensions/?options=' + chrome.runtime.id;
10 chrome.test.listenOnce(chrome.runtime.onMessage, function(m, sender) { 13
11 assertEq('success', m); 14 // Finds the Tab for an options page, or null if no options page is open.
12 assertEq(chrome.runtime.id, sender.id); 15 // Asserts that there is at most 1 options page open.
13 assertEq(chrome.runtime.getURL('options.html'), sender.url); 16 // Result is passed to |callback|.
14 }); 17 function findOptionsTab(callback) {
15 chrome.runtime.openOptionsPage(); 18 chrome.tabs.query({url: optionsTabUrl}, pass(function(tabs) {
19 assertTrue(tabs.length <= 1);
20 callback(tabs.length == 0 ? null : tabs[0]);
21 }));
16 } 22 }
17 23
18 chrome.test.runTests([test]); 24 // Tests opening a new options page.
25 function testNewOptionsPage() {
26 findOptionsTab(function(tab) {
27 assertEq(null, tab);
28 listenOnce(chrome.runtime.onMessage, function(m, sender) {
29 assertEq('success', m);
30 assertEq(chrome.runtime.id, sender.id);
31 assertEq(chrome.runtime.getURL('options.html'), sender.url);
32 });
33 chrome.runtime.openOptionsPage();
34 });
35 }
36
37 // Gets the active tab, or null if no tab is active. Asserts that there is at
38 // most 1 active tab. Result is passed to |callback|.
39 function getActiveTab(callback) {
40 chrome.tabs.query({active: true}, pass(function(tabs) {
41 assertTrue(tabs.length <= 1);
42 callback(tabs.length == 0 ? null : tabs[0]);
43 }));
44 }
45
46 // Tests refocusing an existing page.
47 function testRefocusExistingOptionsPage() {
48 var testUrl = 'chrome://chrome/';
49
50 // There will already be an options page open from the last test. Find it,
51 // focus away from it, then make sure openOptionsPage() refocuses it.
52 findOptionsTab(function(optionsTab) {
53 assertTrue(optionsTab != null);
54 chrome.tabs.create({url: testUrl}, pass(function(tab) {
55 // Make sure the new tab is active.
56 getActiveTab(function(activeTab) {
57 assertEq(testUrl, activeTab.url);
58 // Open options page should refocus it.
59 chrome.runtime.openOptionsPage();
60 getActiveTab(function(activeTab) {
61 assertEq(optionsTabUrl, activeTab.url);
62 });
63 });
64 }));
65 });
66 }
67
68 chrome.test.runTests([testNewOptionsPage, testRefocusExistingOptionsPage]);
OLDNEW
« 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