OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 // Checks that there is only one window and one tab, and calls back |callback| | |
6 // with its id (or -1 if there is more than 1 window or more than 1 tab). | |
7 function getCurrentSingleTabId(callback) { | |
8 chrome.windows.getAll({"populate":true}, function(windows) { | |
9 if (windows.length != 1 || windows[0].tabs.length != 1) { | |
10 callback(-1); | |
11 } else { | |
12 callback(windows[0].tabs[0].id); | |
13 } | |
14 }); | |
15 } | |
16 | |
17 function navigateCurrentTab(url) { | |
18 getCurrentSingleTabId(function(tabid) { | |
19 chrome.tabs.update(tabid, {"url": url}); | |
20 }); | |
21 } | |
22 | |
23 var make_browsertest_proceed = function() { | 5 var make_browsertest_proceed = function() { |
24 if (!chrome.extension.lastError) { | 6 if (!chrome.extension.lastError) { |
25 navigateCurrentTab(chrome.extension.getURL("test.html")); | 7 chrome.test.sendMessage("created items"); |
26 } | 8 } |
27 }; | 9 }; |
28 | 10 |
29 var patterns = ["http://*.google.com/*", "https://*.google.com/*"]; | 11 var patterns = ["http://*.google.com/*", "https://*.google.com/*"]; |
30 | 12 |
31 window.onload = function() { | 13 window.onload = function() { |
32 // Create one item that does have a documentUrlPattern and targetUrlPattern. | 14 // Create one item that does have a documentUrlPattern and targetUrlPattern. |
33 var properties1 = { | 15 var properties1 = { |
34 "title": "test_item1", "documentUrlPatterns": patterns, | 16 "title": "test_item1", "documentUrlPatterns": patterns, |
35 "targetUrlPatterns": patterns | 17 "targetUrlPatterns": patterns |
36 }; | 18 }; |
37 chrome.contextMenus.create(properties1); | 19 chrome.contextMenus.create(properties1); |
38 | 20 |
39 // Create an item that initially doesn't have a documentUrlPattern and | 21 // Create an item that initially doesn't have a documentUrlPattern and |
40 // targetUrlPattern, then update it, and trigger the rest of the c++ code in | 22 // targetUrlPattern, then update it, and trigger the rest of the c++ code in |
41 // the browser test by navigating the tab. | 23 // the browser test by navigating the tab. |
42 var properties2 = { "title": "test_item2" }; | 24 var properties2 = { "title": "test_item2" }; |
43 | 25 |
44 var id2; | 26 var id2; |
45 id2 = chrome.contextMenus.create(properties2, | 27 id2 = chrome.contextMenus.create(properties2, |
46 function() { | 28 function() { |
47 var update_properties = { "documentUrlPatterns": patterns, | 29 var update_properties = { "documentUrlPatterns": patterns, |
48 "targetUrlPatterns": patterns }; | 30 "targetUrlPatterns": patterns }; |
49 chrome.contextMenus.update(id2, update_properties, | 31 chrome.contextMenus.update(id2, update_properties, |
50 make_browsertest_proceed); | 32 make_browsertest_proceed); |
51 }); | 33 }); |
52 }; | 34 }; |
OLD | NEW |