diff options
author | mpcomplete@chromium.org <mpcomplete@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-02-25 22:10:50 +0000 |
---|---|---|
committer | mpcomplete@chromium.org <mpcomplete@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-02-25 22:10:50 +0000 |
commit | db7331aecb1f0c01aecf4cd4627d08a8d5b08bc2 (patch) | |
tree | 5a33fc21cb1628462f9e365add27aeaf058d60fc /chrome/browser/extensions/extension_incognito_apitest.cc | |
parent | f56abff188b90b7f2d67a094930d7d9407df507d (diff) | |
download | chromium_src-db7331aecb1f0c01aecf4cd4627d08a8d5b08bc2.zip chromium_src-db7331aecb1f0c01aecf4cd4627d08a8d5b08bc2.tar.gz chromium_src-db7331aecb1f0c01aecf4cd4627d08a8d5b08bc2.tar.bz2 |
Allow users to enable extensions in incognito. Requires
--enable-experimental-extension-apis . The UI needs work. Tab and window
events are hooked up so that they work with incognito tabs/windows when
enabled.
BUG=32365
BUG=36292
Review URL: http://codereview.chromium.org/657041
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@40057 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/extensions/extension_incognito_apitest.cc')
-rwxr-xr-x | chrome/browser/extensions/extension_incognito_apitest.cc | 144 |
1 files changed, 144 insertions, 0 deletions
diff --git a/chrome/browser/extensions/extension_incognito_apitest.cc b/chrome/browser/extensions/extension_incognito_apitest.cc new file mode 100755 index 0000000..29de8fb --- /dev/null +++ b/chrome/browser/extensions/extension_incognito_apitest.cc @@ -0,0 +1,144 @@ +// 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 "chrome/browser/browser.h" +#include "chrome/browser/browser_list.h" +#include "chrome/browser/browser_window.h" +#include "chrome/browser/extensions/browser_action_test_util.h" +#include "chrome/browser/extensions/extension_apitest.h" +#include "chrome/browser/extensions/extensions_service.h" +#include "chrome/browser/extensions/user_script_master.h" +#include "chrome/browser/profile.h" +#include "chrome/browser/tab_contents/tab_contents.h" +#include "chrome/common/chrome_switches.h" +#include "chrome/common/url_constants.h" +#include "chrome/test/ui_test_utils.h" +#include "net/base/mock_host_resolver.h" + +IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, IncognitoNoScript) { + host_resolver()->AddRule("*", "127.0.0.1"); + StartHTTPServer(); + + // Loads a simple extension which attempts to change the title of every page + // that loads to "modified". + CommandLine::ForCurrentProcess()->AppendSwitch( + switches::kEnableExperimentalExtensionApis); + ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("api_test") + .AppendASCII("incognito").AppendASCII("content_scripts"))); + + // Open incognito window and navigate to test page. + ui_test_utils::OpenURLOffTheRecord(browser()->profile(), + GURL("http://www.example.com:1337/files/extensions/test_file.html")); + Browser* otr_browser = BrowserList::FindBrowserWithType( + browser()->profile()->GetOffTheRecordProfile(), Browser::TYPE_NORMAL); + TabContents* tab = otr_browser->GetSelectedTabContents(); + + // Verify the script didn't run. + bool result = false; + ui_test_utils::ExecuteJavaScriptAndExtractBool( + tab->render_view_host(), L"", + L"window.domAutomationController.send(document.title == 'Unmodified')", + &result); + EXPECT_TRUE(result); +} + +IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, IncognitoYesScript) { + host_resolver()->AddRule("*", "127.0.0.1"); + StartHTTPServer(); + + // Load a dummy extension. This just tests that we don't regress a + // crash fix when multiple incognito- and non-incognito-enabled extensions + // are mixed. + ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("api_test") + .AppendASCII("content_scripts").AppendASCII("all_frames"))); + + // Loads a simple extension which attempts to change the title of every page + // that loads to "modified". + CommandLine::ForCurrentProcess()->AppendSwitch( + switches::kEnableExperimentalExtensionApis); + ASSERT_TRUE(LoadExtensionIncognito(test_data_dir_.AppendASCII("api_test") + .AppendASCII("incognito").AppendASCII("content_scripts"))); + + // Dummy extension #2. + ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("api_test") + .AppendASCII("content_scripts").AppendASCII("isolated_world1"))); + + // Open incognito window and navigate to test page. + ui_test_utils::OpenURLOffTheRecord(browser()->profile(), + GURL("http://www.example.com:1337/files/extensions/test_file.html")); + Browser* otr_browser = BrowserList::FindBrowserWithType( + browser()->profile()->GetOffTheRecordProfile(), Browser::TYPE_NORMAL); + TabContents* tab = otr_browser->GetSelectedTabContents(); + + // Verify the script ran. + bool result = false; + ui_test_utils::ExecuteJavaScriptAndExtractBool( + tab->render_view_host(), L"", + L"window.domAutomationController.send(document.title == 'modified')", + &result); + EXPECT_TRUE(result); +} + +// Tests that the APIs in an incognito-enabled extension work properly. +IN_PROC_BROWSER_TEST_F(ExtensionApiTest, Incognito) { + host_resolver()->AddRule("*", "127.0.0.1"); + StartHTTPServer(); + + ResultCatcher catcher; + + // Open incognito window and navigate to test page. + ui_test_utils::OpenURLOffTheRecord(browser()->profile(), + GURL("http://www.example.com:1337/files/extensions/test_file.html")); + + CommandLine::ForCurrentProcess()->AppendSwitch( + switches::kEnableExperimentalExtensionApis); + ASSERT_TRUE(LoadExtensionIncognito(test_data_dir_ + .AppendASCII("incognito").AppendASCII("apis"))); + + EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); +} + +// Tests that the APIs in an incognito-disabled extension don't see incognito +// events or callbacks. +IN_PROC_BROWSER_TEST_F(ExtensionApiTest, IncognitoDisabled) { + host_resolver()->AddRule("*", "127.0.0.1"); + StartHTTPServer(); + + ResultCatcher catcher; + + // Open incognito window and navigate to test page. + ui_test_utils::OpenURLOffTheRecord(browser()->profile(), + GURL("http://www.example.com:1337/files/extensions/test_file.html")); + + CommandLine::ForCurrentProcess()->AppendSwitch( + switches::kEnableExperimentalExtensionApis); + ASSERT_TRUE(LoadExtension(test_data_dir_ + .AppendASCII("incognito").AppendASCII("apis_disabled"))); + + EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); +} + +// Test that opening a popup from an incognito browser window works properly. +IN_PROC_BROWSER_TEST_F(ExtensionApiTest, IncognitoPopup) { + host_resolver()->AddRule("*", "127.0.0.1"); + StartHTTPServer(); + + ResultCatcher catcher; + + CommandLine::ForCurrentProcess()->AppendSwitch( + switches::kEnableExperimentalExtensionApis); + ASSERT_TRUE(LoadExtensionIncognito(test_data_dir_ + .AppendASCII("incognito").AppendASCII("popup"))); + + // Open incognito window and navigate to test page. + ui_test_utils::OpenURLOffTheRecord(browser()->profile(), + GURL("http://www.example.com:1337/files/extensions/test_file.html")); + Browser* incognito_browser = BrowserList::FindBrowserWithType( + browser()->profile()->GetOffTheRecordProfile(), Browser::TYPE_NORMAL); + + // Simulate the incognito's browser action being clicked. + BrowserActionTestUtil(incognito_browser).Press(0); + + EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); +} |