This source file includes following definitions.
- SetUpCommandLine
- SetUpOnMainThread
- GetExtensionDisabledGlobalError
- InstallIncreasingPermissionExtensionV1
- UpdateIncreasingPermissionExtension
- InstallAndUpdateIncreasingPermissionsExtension
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
#include "base/files/file_path.h"
#include "base/files/scoped_temp_dir.h"
#include "base/run_loop.h"
#include "base/threading/sequenced_worker_pool.h"
#include "chrome/app/chrome_command_ids.h"
#include "chrome/browser/extensions/extension_browsertest.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/extensions/extension_sync_service.h"
#include "chrome/browser/extensions/updater/extension_updater.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/global_error/global_error.h"
#include "chrome/browser/ui/global_error/global_error_service.h"
#include "chrome/browser/ui/global_error/global_error_service_factory.h"
#include "chrome/common/chrome_switches.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/test/test_utils.h"
#include "content/test/net/url_request_prepackaged_interceptor.h"
#include "extensions/browser/extension_prefs.h"
#include "extensions/browser/extension_registry.h"
#include "extensions/common/extension.h"
#include "net/url_request/url_fetcher.h"
using extensions::Extension;
using extensions::ExtensionRegistry;
using extensions::ExtensionPrefs;
class ExtensionDisabledGlobalErrorTest : public ExtensionBrowserTest {
protected:
virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
ExtensionBrowserTest::SetUpCommandLine(command_line);
command_line->AppendSwitchASCII(switches::kAppsGalleryUpdateURL,
"http://localhost/autoupdate/updates.xml");
}
virtual void SetUpOnMainThread() OVERRIDE {
EXPECT_TRUE(scoped_temp_dir_.CreateUniqueTempDir());
service_ = browser()->profile()->GetExtensionService();
registry_ = ExtensionRegistry::Get(browser()->profile());
base::FilePath pem_path = test_data_dir_.
AppendASCII("permissions_increase").AppendASCII("permissions.pem");
path_v1_ = PackExtensionWithOptions(
test_data_dir_.AppendASCII("permissions_increase").AppendASCII("v1"),
scoped_temp_dir_.path().AppendASCII("permissions1.crx"),
pem_path,
base::FilePath());
path_v2_ = PackExtensionWithOptions(
test_data_dir_.AppendASCII("permissions_increase").AppendASCII("v2"),
scoped_temp_dir_.path().AppendASCII("permissions2.crx"),
pem_path,
base::FilePath());
path_v3_ = PackExtensionWithOptions(
test_data_dir_.AppendASCII("permissions_increase").AppendASCII("v3"),
scoped_temp_dir_.path().AppendASCII("permissions3.crx"),
pem_path,
base::FilePath());
}
GlobalError* GetExtensionDisabledGlobalError() {
return GlobalErrorServiceFactory::GetForProfile(browser()->profile())->
GetGlobalErrorByMenuItemCommandID(IDC_EXTENSION_DISABLED_FIRST);
}
const Extension* InstallIncreasingPermissionExtensionV1() {
size_t size_before = registry_->enabled_extensions().size();
const Extension* extension = InstallExtension(path_v1_, 1);
if (!extension)
return NULL;
if (registry_->enabled_extensions().size() != size_before + 1)
return NULL;
return extension;
}
const Extension* UpdateIncreasingPermissionExtension(
const Extension* extension,
const base::FilePath& crx_path,
int expected_change) {
size_t size_before = registry_->enabled_extensions().size();
if (UpdateExtension(extension->id(), crx_path, expected_change))
return NULL;
content::BrowserThread::GetBlockingPool()->FlushForTesting();
base::RunLoop().RunUntilIdle();
EXPECT_EQ(size_before + expected_change,
registry_->enabled_extensions().size());
if (registry_->disabled_extensions().size() != 1u)
return NULL;
return registry_->disabled_extensions().begin()->get();
}
const Extension* InstallAndUpdateIncreasingPermissionsExtension() {
const Extension* extension = InstallIncreasingPermissionExtensionV1();
extension = UpdateIncreasingPermissionExtension(extension, path_v2_, -1);
return extension;
}
ExtensionService* service_;
ExtensionRegistry* registry_;
base::ScopedTempDir scoped_temp_dir_;
base::FilePath path_v1_;
base::FilePath path_v2_;
base::FilePath path_v3_;
};
IN_PROC_BROWSER_TEST_F(ExtensionDisabledGlobalErrorTest, AcceptPermissions) {
const Extension* extension = InstallAndUpdateIncreasingPermissionsExtension();
ASSERT_TRUE(extension);
ASSERT_TRUE(GetExtensionDisabledGlobalError());
const size_t size_before = registry_->enabled_extensions().size();
service_->GrantPermissionsAndEnableExtension(extension);
EXPECT_EQ(size_before + 1, registry_->enabled_extensions().size());
EXPECT_EQ(0u, registry_->disabled_extensions().size());
ASSERT_FALSE(GetExtensionDisabledGlobalError());
}
IN_PROC_BROWSER_TEST_F(ExtensionDisabledGlobalErrorTest, Uninstall) {
const Extension* extension = InstallAndUpdateIncreasingPermissionsExtension();
ASSERT_TRUE(extension);
ASSERT_TRUE(GetExtensionDisabledGlobalError());
const size_t size_before = registry_->enabled_extensions().size();
UninstallExtension(extension->id());
EXPECT_EQ(size_before, registry_->enabled_extensions().size());
EXPECT_EQ(0u, registry_->disabled_extensions().size());
ASSERT_FALSE(GetExtensionDisabledGlobalError());
}
IN_PROC_BROWSER_TEST_F(ExtensionDisabledGlobalErrorTest, UserDisabled) {
const Extension* extension = InstallIncreasingPermissionExtensionV1();
DisableExtension(extension->id());
extension = UpdateIncreasingPermissionExtension(extension, path_v2_, 0);
ASSERT_FALSE(GetExtensionDisabledGlobalError());
}
IN_PROC_BROWSER_TEST_F(ExtensionDisabledGlobalErrorTest,
UnknownReasonSamePermissions) {
const Extension* extension = InstallIncreasingPermissionExtensionV1();
DisableExtension(extension->id());
ExtensionPrefs::Get(browser()->profile())
->ClearDisableReasons(extension->id());
extension = UpdateIncreasingPermissionExtension(extension, path_v2_, 0);
ASSERT_TRUE(extension);
ASSERT_FALSE(GetExtensionDisabledGlobalError());
}
IN_PROC_BROWSER_TEST_F(ExtensionDisabledGlobalErrorTest,
UnknownReasonHigherPermissions) {
const Extension* extension = InstallAndUpdateIncreasingPermissionsExtension();
ExtensionPrefs::Get(service_->profile())
->ClearDisableReasons(extension->id());
GlobalError* error = GetExtensionDisabledGlobalError();
ASSERT_TRUE(error);
GlobalErrorServiceFactory::GetForProfile(browser()->profile())->
RemoveGlobalError(error);
delete error;
extension = UpdateIncreasingPermissionExtension(extension, path_v3_, 0);
ASSERT_TRUE(extension);
ASSERT_TRUE(GetExtensionDisabledGlobalError());
}
IN_PROC_BROWSER_TEST_F(ExtensionDisabledGlobalErrorTest,
HigherPermissionsFromSync) {
const Extension* extension = InstallAndUpdateIncreasingPermissionsExtension();
std::string extension_id = extension->id();
ExtensionSyncService* sync_service = ExtensionSyncService::Get(
browser()->profile());
extensions::ExtensionSyncData sync_data =
sync_service->GetExtensionSyncData(*extension);
UninstallExtension(extension_id);
extension = NULL;
InstallIncreasingPermissionExtensionV1();
content::URLLocalHostRequestPrepackagedInterceptor interceptor;
net::URLFetcher::SetEnableInterceptionForTests(true);
interceptor.SetResponseIgnoreQuery(
GURL("http://localhost/autoupdate/updates.xml"),
test_data_dir_.AppendASCII("permissions_increase")
.AppendASCII("updates.xml"));
interceptor.SetResponseIgnoreQuery(
GURL("http://localhost/autoupdate/v2.crx"),
scoped_temp_dir_.path().AppendASCII("permissions2.crx"));
extensions::ExtensionUpdater::CheckParams params;
service_->updater()->set_default_check_params(params);
EXPECT_FALSE(sync_service->ProcessExtensionSyncData(sync_data));
WaitForExtensionInstall();
content::BrowserThread::GetBlockingPool()->FlushForTesting();
base::RunLoop().RunUntilIdle();
extension = service_->GetExtensionById(extension_id, true);
ASSERT_TRUE(extension);
EXPECT_EQ("2", extension->VersionString());
EXPECT_EQ(1u, registry_->disabled_extensions().size());
EXPECT_EQ(Extension::DISABLE_PERMISSIONS_INCREASE,
ExtensionPrefs::Get(service_->profile())
->GetDisableReasons(extension_id));
EXPECT_TRUE(GetExtensionDisabledGlobalError());
}