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

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

Issue 709813004: Remove the deprecated function ExtensionService::extensions(). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 1 month 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "base/command_line.h" 5 #include "base/command_line.h"
6 #include "base/scoped_observer.h" 6 #include "base/scoped_observer.h"
7 #include "chrome/browser/chrome_notification_types.h" 7 #include "chrome/browser/chrome_notification_types.h"
8 #include "chrome/browser/extensions/extension_install_prompt.h" 8 #include "chrome/browser/extensions/extension_install_prompt.h"
9 #include "chrome/browser/extensions/extension_service.h" 9 #include "chrome/browser/extensions/extension_service.h"
10 #include "chrome/browser/extensions/startup_helper.h" 10 #include "chrome/browser/extensions/startup_helper.h"
(...skipping 18 matching lines...) Expand all
29 #include "extensions/browser/install/extension_install_ui.h" 29 #include "extensions/browser/install/extension_install_ui.h"
30 #include "extensions/common/extension_builder.h" 30 #include "extensions/common/extension_builder.h"
31 #include "extensions/common/value_builder.h" 31 #include "extensions/common/value_builder.h"
32 #include "net/dns/mock_host_resolver.h" 32 #include "net/dns/mock_host_resolver.h"
33 #include "url/gurl.h" 33 #include "url/gurl.h"
34 34
35 using content::WebContents; 35 using content::WebContents;
36 using extensions::DictionaryBuilder; 36 using extensions::DictionaryBuilder;
37 using extensions::Extension; 37 using extensions::Extension;
38 using extensions::ExtensionBuilder; 38 using extensions::ExtensionBuilder;
39 using extensions::ExtensionRegistry;
39 using extensions::ListBuilder; 40 using extensions::ListBuilder;
40 41
41 const char kWebstoreDomain[] = "cws.com"; 42 const char kWebstoreDomain[] = "cws.com";
42 const char kAppDomain[] = "app.com"; 43 const char kAppDomain[] = "app.com";
43 const char kNonAppDomain[] = "nonapp.com"; 44 const char kNonAppDomain[] = "nonapp.com";
44 const char kTestExtensionId[] = "ecglahbcnmdpdciemllbhojghbkagdje"; 45 const char kTestExtensionId[] = "ecglahbcnmdpdciemllbhojghbkagdje";
45 const char kTestDataPath[] = "extensions/api_test/webstore_inline_install"; 46 const char kTestDataPath[] = "extensions/api_test/webstore_inline_install";
46 const char kCrxFilename[] = "extension.crx"; 47 const char kCrxFilename[] = "extension.crx";
47 48
48 class WebstoreStartupInstallerTest : public WebstoreInstallerTest { 49 class WebstoreStartupInstallerTest : public WebstoreInstallerTest {
(...skipping 10 matching lines...) Expand all
59 IN_PROC_BROWSER_TEST_F(WebstoreStartupInstallerTest, Install) { 60 IN_PROC_BROWSER_TEST_F(WebstoreStartupInstallerTest, Install) {
60 ExtensionInstallPrompt::g_auto_confirm_for_tests = 61 ExtensionInstallPrompt::g_auto_confirm_for_tests =
61 ExtensionInstallPrompt::ACCEPT; 62 ExtensionInstallPrompt::ACCEPT;
62 63
63 ui_test_utils::NavigateToURL( 64 ui_test_utils::NavigateToURL(
64 browser(), GenerateTestServerUrl(kAppDomain, "install.html")); 65 browser(), GenerateTestServerUrl(kAppDomain, "install.html"));
65 66
66 RunTest("runTest"); 67 RunTest("runTest");
67 68
68 const extensions::Extension* extension = 69 const extensions::Extension* extension =
69 extensions::ExtensionRegistry::Get( 70 ExtensionRegistry::Get(browser()->profile())
70 browser()->profile())->enabled_extensions().GetByID(kTestExtensionId); 71 ->GetExtensionById(kTestExtensionId, ExtensionRegistry::ENABLED);
71 EXPECT_TRUE(extension); 72 EXPECT_TRUE(extension);
72 } 73 }
73 74
74 IN_PROC_BROWSER_TEST_F(WebstoreStartupInstallerTest, 75 IN_PROC_BROWSER_TEST_F(WebstoreStartupInstallerTest,
75 InstallNotAllowedFromNonVerifiedDomains) { 76 InstallNotAllowedFromNonVerifiedDomains) {
76 ExtensionInstallPrompt::g_auto_confirm_for_tests = 77 ExtensionInstallPrompt::g_auto_confirm_for_tests =
77 ExtensionInstallPrompt::CANCEL; 78 ExtensionInstallPrompt::CANCEL;
78 ui_test_utils::NavigateToURL( 79 ui_test_utils::NavigateToURL(
79 browser(), 80 browser(),
80 GenerateTestServerUrl(kNonAppDomain, "install_non_verified_domain.html")); 81 GenerateTestServerUrl(kNonAppDomain, "install_non_verified_domain.html"));
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 .Set("urls", ListBuilder().Append(kInstallUrl.spec())) 156 .Set("urls", ListBuilder().Append(kInstallUrl.spec()))
156 .Set("launch", DictionaryBuilder() 157 .Set("launch", DictionaryBuilder()
157 .Set("web_url", kInstallUrl.spec()))) 158 .Set("web_url", kInstallUrl.spec())))
158 .Set("manifest_version", 2)) 159 .Set("manifest_version", 2))
159 .Build(); 160 .Build();
160 ASSERT_TRUE(hosted_app.get()); 161 ASSERT_TRUE(hosted_app.get());
161 162
162 ExtensionService* extension_service = 163 ExtensionService* extension_service =
163 extensions::ExtensionSystem::Get(browser()->profile())-> 164 extensions::ExtensionSystem::Get(browser()->profile())->
164 extension_service(); 165 extension_service();
166 ExtensionRegistry* registry = ExtensionRegistry::Get(browser()->profile());
165 167
166 extension_service->AddExtension(hosted_app.get()); 168 extension_service->AddExtension(hosted_app.get());
167 EXPECT_TRUE(extension_service->extensions()->Contains(hosted_app->id())); 169 EXPECT_TRUE(registry->GetExtensionById(
170 hosted_app->id(), ExtensionRegistry::ENABLED));
168 171
169 ui_test_utils::NavigateToURL(browser(), kInstallUrl); 172 ui_test_utils::NavigateToURL(browser(), kInstallUrl);
170 173
171 EXPECT_FALSE(extension_service->extensions()->Contains(kTestExtensionId)); 174 EXPECT_FALSE(registry->GetExtensionById(
175 kTestExtensionId, ExtensionRegistry::ENABLED));
172 RunTest("runTest"); 176 RunTest("runTest");
173 EXPECT_TRUE(extension_service->extensions()->Contains(kTestExtensionId)); 177 EXPECT_TRUE(registry->GetExtensionById(
178 kTestExtensionId, ExtensionRegistry::ENABLED));
174 } 179 }
175 180
176 class WebstoreStartupInstallerSupervisedUsersTest 181 class WebstoreStartupInstallerSupervisedUsersTest
177 : public WebstoreStartupInstallerTest { 182 : public WebstoreStartupInstallerTest {
178 public: 183 public:
179 // InProcessBrowserTest overrides: 184 // InProcessBrowserTest overrides:
180 void SetUpCommandLine(base::CommandLine* command_line) override { 185 void SetUpCommandLine(base::CommandLine* command_line) override {
181 WebstoreStartupInstallerTest::SetUpCommandLine(command_line); 186 WebstoreStartupInstallerTest::SetUpCommandLine(command_line);
182 command_line->AppendSwitchASCII(switches::kSupervisedUserId, "asdf"); 187 command_line->AppendSwitchASCII(switches::kSupervisedUserId, "asdf");
183 } 188 }
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 class CommandLineWebstoreInstall 245 class CommandLineWebstoreInstall
241 : public WebstoreStartupInstallerTest, 246 : public WebstoreStartupInstallerTest,
242 public content::NotificationObserver, 247 public content::NotificationObserver,
243 public extensions::ExtensionRegistryObserver { 248 public extensions::ExtensionRegistryObserver {
244 public: 249 public:
245 CommandLineWebstoreInstall() : saw_install_(false), browser_open_count_(0) {} 250 CommandLineWebstoreInstall() : saw_install_(false), browser_open_count_(0) {}
246 ~CommandLineWebstoreInstall() override {} 251 ~CommandLineWebstoreInstall() override {}
247 252
248 void SetUpOnMainThread() override { 253 void SetUpOnMainThread() override {
249 WebstoreStartupInstallerTest::SetUpOnMainThread(); 254 WebstoreStartupInstallerTest::SetUpOnMainThread();
250 extensions::ExtensionRegistry::Get(browser()->profile())->AddObserver(this); 255 ExtensionRegistry::Get(browser()->profile())->AddObserver(this);
251 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_OPENED, 256 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_OPENED,
252 content::NotificationService::AllSources()); 257 content::NotificationService::AllSources());
253 } 258 }
254 259
255 void TearDownOnMainThread() override { 260 void TearDownOnMainThread() override {
256 extensions::ExtensionRegistry::Get(browser()->profile()) 261 ExtensionRegistry::Get(browser()->profile())->RemoveObserver(this);
257 ->RemoveObserver(this);
258 WebstoreStartupInstallerTest::TearDownOnMainThread(); 262 WebstoreStartupInstallerTest::TearDownOnMainThread();
259 } 263 }
260 264
261 bool saw_install() { return saw_install_; } 265 bool saw_install() { return saw_install_; }
262 266
263 int browser_open_count() { return browser_open_count_; } 267 int browser_open_count() { return browser_open_count_; }
264 268
265 // NotificationObserver interface. 269 // NotificationObserver interface.
266 void Observe(int type, 270 void Observe(int type,
267 const content::NotificationSource& source, 271 const content::NotificationSource& source,
(...skipping 24 matching lines...) Expand all
292 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); 296 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
293 command_line->AppendSwitchASCII( 297 command_line->AppendSwitchASCII(
294 switches::kInstallEphemeralAppFromWebstore, kTestExtensionId); 298 switches::kInstallEphemeralAppFromWebstore, kTestExtensionId);
295 ExtensionInstallPrompt::g_auto_confirm_for_tests = 299 ExtensionInstallPrompt::g_auto_confirm_for_tests =
296 ExtensionInstallPrompt::ACCEPT; 300 ExtensionInstallPrompt::ACCEPT;
297 extensions::StartupHelper helper; 301 extensions::StartupHelper helper;
298 EXPECT_FALSE(helper.InstallEphemeralApp(*command_line, browser()->profile())); 302 EXPECT_FALSE(helper.InstallEphemeralApp(*command_line, browser()->profile()));
299 EXPECT_FALSE(saw_install()); 303 EXPECT_FALSE(saw_install());
300 EXPECT_EQ(0, browser_open_count()); 304 EXPECT_EQ(0, browser_open_count());
301 } 305 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698