diff options
19 files changed, 236 insertions, 13 deletions
diff --git a/chrome/browser/extensions/extension_get_views_apitest.cc b/chrome/browser/extensions/extension_get_views_apitest.cc new file mode 100644 index 0000000..8f1ced3 --- /dev/null +++ b/chrome/browser/extensions/extension_get_views_apitest.cc @@ -0,0 +1,23 @@ +// 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. + +#include "base/command_line.h" +#include "chrome/browser/extensions/extension_apitest.h" +#include "chrome/common/chrome_switches.h" + +#if defined(TOOLKIT_VIEWS) +// Need to port ExtensionInfoBarDelegate::CreateInfoBar() to other platforms. +// See http://crbug.com/39916 for details. +#define MAYBE_GetViews GetViews +#else +#define MAYBE_GetViews DISABLED_GetViews +#endif + +IN_PROC_BROWSER_TEST_F(ExtensionApiTest, MAYBE_GetViews) { + // TODO(finnur): Remove once infobars are no longer experimental (bug 39511). + CommandLine::ForCurrentProcess()->AppendSwitch( + switches::kEnableExperimentalExtensionApis); + + ASSERT_TRUE(RunExtensionTest("get_views")) << message_; +} diff --git a/chrome/browser/extensions/extension_infobar_apitest.cc b/chrome/browser/extensions/extension_infobar_apitest.cc new file mode 100644 index 0000000..776b3a2 --- /dev/null +++ b/chrome/browser/extensions/extension_infobar_apitest.cc @@ -0,0 +1,23 @@ +// 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. + +#include "base/command_line.h" +#include "chrome/browser/extensions/extension_apitest.h" +#include "chrome/common/chrome_switches.h" + +#if defined(TOOLKIT_VIEWS) +// Need to port ExtensionInfoBarDelegate::CreateInfoBar() to other platforms. +// See http://crbug.com/39916 for details. +#define MAYBE_Infobars Infobars +#else +#define MAYBE_Infobars DISABLED_Infobars +#endif + +IN_PROC_BROWSER_TEST_F(ExtensionApiTest, MAYBE_Infobars) { + // TODO(finnur): Remove once infobars are no longer experimental (bug 39511). + CommandLine::ForCurrentProcess()->AppendSwitch( + switches::kEnableExperimentalExtensionApis); + + ASSERT_TRUE(RunExtensionTest("infobars")) << message_; +} diff --git a/chrome/browser/extensions/extension_infobar_module.cc b/chrome/browser/extensions/extension_infobar_module.cc index 01eec16..73768fb 100644 --- a/chrome/browser/extensions/extension_infobar_module.cc +++ b/chrome/browser/extensions/extension_infobar_module.cc @@ -29,24 +29,25 @@ bool ShowInfoBarFunction::RunImpl() { Extension* extension = dispatcher()->GetExtension(); GURL url = extension->GetResourceURL(extension->url(), html_path); - Browser* browser = dispatcher()->GetCurrentBrowser(true); - if (!browser) { - error_ = keys::kNoCurrentWindowError; - return false; - } - + Browser* browser = NULL; TabContents* tab_contents = NULL; if (args->HasKey(keys::kTabId)) { int tab_id = -1; EXTENSION_FUNCTION_VALIDATE(args->GetInteger(keys::kTabId, &tab_id)); EXTENSION_FUNCTION_VALIDATE(ExtensionTabUtil::GetTabById( - tab_id, browser->profile(), true, // Allow infobar in incognito. - NULL, NULL, &tab_contents, NULL)); + tab_id, profile(), true, // Allow infobar in incognito. + &browser, NULL, &tab_contents, NULL)); } else { + browser = dispatcher()->GetCurrentBrowser(true); tab_contents = browser->GetSelectedTabContents(); } + if (!browser) { + error_ = keys::kNoCurrentWindowError; + return false; + } + if (!tab_contents) { error_ = keys::kTabNotFoundError; return false; diff --git a/chrome/browser/extensions/extension_infobar_module_constants.cc b/chrome/browser/extensions/extension_infobar_module_constants.cc index d628c48..1b0eef9 100644 --- a/chrome/browser/extensions/extension_infobar_module_constants.cc +++ b/chrome/browser/extensions/extension_infobar_module_constants.cc @@ -6,7 +6,7 @@ namespace extension_infobar_module_constants { -const wchar_t kHtmlPath[] = L"htmlPath"; +const wchar_t kHtmlPath[] = L"path"; const wchar_t kTabId[] = L"tabId"; const char kNoCurrentWindowError[] = "No current browser window was found"; diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi index df8bad2..53ca3d5 100644 --- a/chrome/chrome_tests.gypi +++ b/chrome/chrome_tests.gypi @@ -1234,10 +1234,12 @@ 'browser/extensions/extension_clipboard_apitest.cc', 'browser/extensions/extension_crash_recovery_browsertest.cc', 'browser/extensions/extension_geolocation_apitest.cc', + 'browser/extensions/extension_get_views_apitest.cc', 'browser/extensions/extension_history_apitest.cc', 'browser/extensions/extension_idle_apitest.cc', 'browser/extensions/extension_i18n_apitest.cc', 'browser/extensions/extension_incognito_apitest.cc', + 'browser/extensions/extension_infobar_apitest.cc', 'browser/extensions/extension_javascript_url_apitest.cc', 'browser/extensions/extension_management_tests.cc', 'browser/extensions/extension_messages_apitest.cc', diff --git a/chrome/common/extensions/api/extension_api.json b/chrome/common/extensions/api/extension_api.json index 3751f16..50d1491 100755 --- a/chrome/common/extensions/api/extension_api.json +++ b/chrome/common/extensions/api/extension_api.json @@ -1429,7 +1429,7 @@ "description": "The tab id for the tab to display the infobar in. If not specified the current tab will be used.", "optional": true }, - "htmlPath": { + "path": { "type": "string", "description": "The html file that contains the infobar." } diff --git a/chrome/common/extensions/docs/experimental.infobars.html b/chrome/common/extensions/docs/experimental.infobars.html index ff5991b..5779ab7 100644 --- a/chrome/common/extensions/docs/experimental.infobars.html +++ b/chrome/common/extensions/docs/experimental.infobars.html @@ -378,7 +378,7 @@ </div><div> <div> <dt> - <var>htmlPath</var> + <var>path</var> <em> <!-- TYPE --> diff --git a/chrome/renderer/resources/extension_process_bindings.js b/chrome/renderer/resources/extension_process_bindings.js index 5d80919..fe8499c 100644 --- a/chrome/renderer/resources/extension_process_bindings.js +++ b/chrome/renderer/resources/extension_process_bindings.js @@ -419,8 +419,18 @@ var chrome = chrome || {}; }); } - apiFunctions["extension.getViews"].handleRequest = function() { - return GetExtensionViews(-1, "ALL"); + apiFunctions["extension.getViews"].handleRequest = function(properties) { + var windowId = -1; + var type = "ALL"; + if (typeof(properties) != "undefined") { + if (typeof(properties.type) != "undefined") { + type = properties.type; + } + if (typeof(properties.windowId) != "undefined") { + windowId = properties.windowId; + } + } + return GetExtensionViews(windowId, type) || null; } apiFunctions["extension.getBackgroundPage"].handleRequest = function() { 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); |