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

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

Issue 9222013: Prevent unnecessary prompts when unpacked extensions use chrome.permissions.request. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: reword comment Created 8 years, 11 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 | Annotate | Revision Log
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 "chrome/browser/extensions/extension_service_unittest.h" 5 #include "chrome/browser/extensions/extension_service_unittest.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <set> 8 #include <set>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 2299 matching lines...) Expand 10 before | Expand all | Expand 10 after
2310 extensions::UnpackedInstaller::Create(service_)->Load(extension_path); 2310 extensions::UnpackedInstaller::Create(service_)->Load(extension_path);
2311 loop_.RunAllPending(); 2311 loop_.RunAllPending();
2312 2312
2313 EXPECT_EQ(0u, GetErrors().size()); 2313 EXPECT_EQ(0u, GetErrors().size());
2314 ASSERT_EQ(1u, loaded_.size()); 2314 ASSERT_EQ(1u, loaded_.size());
2315 EXPECT_EQ(Extension::LOAD, loaded_[0]->location()); 2315 EXPECT_EQ(Extension::LOAD, loaded_[0]->location());
2316 EXPECT_EQ(1u, service_->extensions()->size()); 2316 EXPECT_EQ(1u, service_->extensions()->size());
2317 EXPECT_EQ("1.0", loaded_[0]->VersionString()); 2317 EXPECT_EQ("1.0", loaded_[0]->VersionString());
2318 } 2318 }
2319 2319
2320 #if !defined(OS_CHROMEOS)
2321 // LOAD extensions with plugins require approval.
2322 TEST_F(ExtensionServiceTest, LoadExtensionsWithPlugins) {
2323 FilePath extension_with_plugin_path = data_dir_
2324 .AppendASCII("good")
2325 .AppendASCII("Extensions")
2326 .AppendASCII(good1)
2327 .AppendASCII("2");
2328 FilePath extension_no_plugin_path = data_dir_
2329 .AppendASCII("good")
2330 .AppendASCII("Extensions")
2331 .AppendASCII(good2)
2332 .AppendASCII("1.0");
2333
2334 PluginService::GetInstance()->Init();
2335 InitializeEmptyExtensionService();
2336 InitializeExtensionProcessManager();
2337 service_->set_show_extensions_prompts(true);
2338
2339 // Start by canceling any install prompts.
2340 CommandLine::ForCurrentProcess()->AppendSwitchASCII(
2341 switches::kAppsGalleryInstallAutoConfirmForTests,
2342 "cancel");
2343
2344 // The extension that has a plugin should not install.
2345 extensions::UnpackedInstaller::Create(service_)->Load(
2346 extension_with_plugin_path);
2347 loop_.RunAllPending();
2348 EXPECT_EQ(0u, GetErrors().size());
2349 EXPECT_EQ(0u, loaded_.size());
2350 EXPECT_EQ(0u, service_->extensions()->size());
2351 EXPECT_EQ(0u, service_->disabled_extensions()->size());
2352
2353 // But the extension with no plugin should since there's no prompt.
2354 extensions::UnpackedInstaller::Create(service_)->Load(
2355 extension_no_plugin_path);
2356 loop_.RunAllPending();
2357 EXPECT_EQ(0u, GetErrors().size());
2358 EXPECT_EQ(1u, loaded_.size());
2359 EXPECT_EQ(1u, service_->extensions()->size());
2360 EXPECT_EQ(0u, service_->disabled_extensions()->size());
2361 EXPECT_TRUE(service_->extensions()->Contains(good2));
2362
2363 // The plugin extension should install if we accept the dialog.
2364 CommandLine::ForCurrentProcess()->AppendSwitchASCII(
2365 switches::kAppsGalleryInstallAutoConfirmForTests,
2366 "accept");
2367
2368 extensions::UnpackedInstaller::Create(service_)->Load(
2369 extension_with_plugin_path);
2370 loop_.RunAllPending();
2371 EXPECT_EQ(0u, GetErrors().size());
2372 EXPECT_EQ(2u, loaded_.size());
2373 EXPECT_EQ(2u, service_->extensions()->size());
2374 EXPECT_EQ(0u, service_->disabled_extensions()->size());
2375 EXPECT_TRUE(service_->extensions()->Contains(good1));
2376 EXPECT_TRUE(service_->extensions()->Contains(good2));
2377
2378 // Make sure the granted permissions have been setup.
2379 scoped_refptr<ExtensionPermissionSet> permissions(
2380 service_->extension_prefs()->GetGrantedPermissions(good1));
2381 EXPECT_FALSE(permissions->IsEmpty());
2382 EXPECT_TRUE(permissions->HasEffectiveFullAccess());
2383 EXPECT_FALSE(permissions->apis().empty());
2384 EXPECT_TRUE(permissions->HasAPIPermission(ExtensionAPIPermission::kPlugin));
2385
2386 // We should be able to reload the extension without getting another prompt.
2387 loaded_.clear();
2388 CommandLine::ForCurrentProcess()->AppendSwitchASCII(
2389 switches::kAppsGalleryInstallAutoConfirmForTests,
2390 "cancel");
2391
2392 service_->ReloadExtension(good1);
2393 loop_.RunAllPending();
2394 EXPECT_EQ(1u, loaded_.size());
2395 EXPECT_EQ(2u, service_->extensions()->size());
2396 EXPECT_EQ(0u, service_->disabled_extensions()->size());
2397 }
2398 #endif
2399
2320 namespace { 2400 namespace {
2321 2401
2322 bool IsExtension(const Extension& extension) { 2402 bool IsExtension(const Extension& extension) {
2323 return extension.GetType() == Extension::TYPE_EXTENSION; 2403 return extension.GetType() == Extension::TYPE_EXTENSION;
2324 } 2404 }
2325 2405
2326 } // namespace 2406 } // namespace
2327 2407
2328 // Test adding a pending extension. 2408 // Test adding a pending extension.
2329 TEST_F(ExtensionServiceTest, AddPendingExtensionFromSync) { 2409 TEST_F(ExtensionServiceTest, AddPendingExtensionFromSync) {
(...skipping 2333 matching lines...) Expand 10 before | Expand all | Expand 10 after
4663 ASSERT_FALSE(AddPendingSyncInstall()); 4743 ASSERT_FALSE(AddPendingSyncInstall());
4664 4744
4665 // Wait for the external source to install. 4745 // Wait for the external source to install.
4666 WaitForCrxInstall(crx_path_, INSTALL_NEW); 4746 WaitForCrxInstall(crx_path_, INSTALL_NEW);
4667 ASSERT_TRUE(IsCrxInstalled()); 4747 ASSERT_TRUE(IsCrxInstalled());
4668 4748
4669 // Now that the extension is installed, sync request should fail 4749 // Now that the extension is installed, sync request should fail
4670 // because the extension is already installed. 4750 // because the extension is already installed.
4671 ASSERT_FALSE(AddPendingSyncInstall()); 4751 ASSERT_FALSE(AddPendingSyncInstall());
4672 } 4752 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/crx_installer.cc ('k') | chrome/browser/extensions/unpacked_installer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698