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

Side by Side Diff: chrome/browser/extensions/incognito_noscript_apitest.cc

Issue 567037: Initial work on making extensions work in incognito mode. (Closed)
Patch Set: added experimental requirement Created 10 years, 10 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
OLDNEW
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 #include "chrome/browser/browser.h" 5 #include "chrome/browser/browser.h"
6 #include "chrome/browser/browser_list.h" 6 #include "chrome/browser/browser_list.h"
7 #include "chrome/browser/browser_window.h" 7 #include "chrome/browser/browser_window.h"
8 #include "chrome/browser/extensions/extension_browsertest.h" 8 #include "chrome/browser/extensions/extension_browsertest.h"
9 #include "chrome/browser/extensions/extensions_service.h"
10 #include "chrome/browser/extensions/user_script_master.h"
9 #include "chrome/browser/profile.h" 11 #include "chrome/browser/profile.h"
10 #include "chrome/browser/tab_contents/tab_contents.h" 12 #include "chrome/browser/tab_contents/tab_contents.h"
13 #include "chrome/common/chrome_switches.h"
11 #include "chrome/common/url_constants.h" 14 #include "chrome/common/url_constants.h"
12 #include "chrome/test/ui_test_utils.h" 15 #include "chrome/test/ui_test_utils.h"
13 #include "net/base/mock_host_resolver.h" 16 #include "net/base/mock_host_resolver.h"
14 17
15 IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, IncognitoNoScript) { 18 IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, IncognitoNoScript) {
16 host_resolver()->AddRule("*", "127.0.0.1"); 19 host_resolver()->AddRule("*", "127.0.0.1");
17 StartHTTPServer(); 20 StartHTTPServer();
18 21
19 // Loads a simple extension which attempts to change the title of every page 22 // Loads a simple extension which attempts to change the title of every page
20 // that loads to "modified". 23 // that loads to "modified".
24 CommandLine::ForCurrentProcess()->AppendSwitch(
25 switches::kEnableExperimentalExtensionApis);
21 FilePath extension_path = test_data_dir_.AppendASCII("api_test") 26 FilePath extension_path = test_data_dir_.AppendASCII("api_test")
22 .AppendASCII("incognito_no_script"); 27 .AppendASCII("incognito_no_script");
23 ASSERT_TRUE(LoadExtension(extension_path)); 28 ASSERT_TRUE(LoadExtension(extension_path));
24 29
25 // Open incognito window and navigate to test page. 30 // Open incognito window and navigate to test page.
26 Browser::OpenURLOffTheRecord(browser()->profile(), 31 ui_test_utils::OpenURLOffTheRecord(browser()->profile(),
27 GURL("http://www.foo.com:1337/files/extensions/test_file.html")); 32 GURL("http://www.example.com:1337/files/extensions/test_file.html"));
28 Profile* off_the_record_profile = 33 Browser* otr_browser = BrowserList::FindBrowserWithType(
29 browser()->profile()->GetOffTheRecordProfile(); 34 browser()->profile()->GetOffTheRecordProfile(), Browser::TYPE_NORMAL);
30 Browser* otr_browser = Browser::Create(off_the_record_profile);
31 otr_browser->AddTabWithURL(
32 GURL("http://www.foo.com:1337/files/extensions/test_file.html"),
33 GURL(),
34 PageTransition::LINK,
35 true,
36 -1,
37 false,
38 NULL);
39 otr_browser->window()->Show();
40 ui_test_utils::WaitForNavigationInCurrentTab(otr_browser);
41 35
42 string16 title; 36 string16 title;
43 ui_test_utils::GetCurrentTabTitle(otr_browser, &title); 37 ui_test_utils::GetCurrentTabTitle(otr_browser, &title);
44 ASSERT_EQ("Unmodified", UTF16ToASCII(title)); 38 ASSERT_EQ("Unmodified", UTF16ToASCII(title));
45 } 39 }
40
41 IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, IncognitoYesScript) {
42 host_resolver()->AddRule("*", "127.0.0.1");
43 StartHTTPServer();
44
45 // Loads a simple extension which attempts to change the title of every page
46 // that loads to "modified".
47 CommandLine::ForCurrentProcess()->AppendSwitch(
48 switches::kEnableExperimentalExtensionApis);
49 FilePath extension_path = test_data_dir_.AppendASCII("api_test")
50 .AppendASCII("incognito_no_script");
51 ASSERT_TRUE(LoadExtension(extension_path));
52
53 // Now enable the extension in incognito mode, and ensure that page titles
54 // are modified.
55 ExtensionsService* service = browser()->profile()->GetExtensionsService();
56 service->extension_prefs()->SetIsIncognitoEnabled(
57 service->extensions()->at(0)->id(), true);
58 browser()->profile()->GetUserScriptMaster()->ReloadExtensionForTesting(
59 service->extensions()->at(0));
60
61 // Open incognito window and navigate to test page.
62 ui_test_utils::OpenURLOffTheRecord(browser()->profile(),
63 GURL("http://www.example.com:1337/files/extensions/test_file.html"));
64 Browser* otr_browser = BrowserList::FindBrowserWithType(
65 browser()->profile()->GetOffTheRecordProfile(), Browser::TYPE_NORMAL);
66
67 string16 title;
68 ui_test_utils::GetCurrentTabTitle(otr_browser, &title);
69 ASSERT_EQ("modified", UTF16ToASCII(title));
70 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extensions_service.cc ('k') | chrome/browser/extensions/user_script_master.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698