Commit 9afc6213 authored by treib's avatar treib Committed by Commit bot

Move the Sync-specific tests from ExtensionServiceTest into a new file

BUG=381251

Review URL: https://codereview.chromium.org/1411773002

Cr-Commit-Position: refs/heads/master@{#357158}
parent b86705bd
This diff is collapsed.
......@@ -8,6 +8,8 @@
#include "base/files/file_util.h"
#include "base/memory/ref_counted.h"
#include "base/path_service.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/stringprintf.h"
#include "base/thread_task_runner_handle.h"
#include "chrome/browser/extensions/component_loader.h"
#include "chrome/browser/extensions/extension_error_reporter.h"
......@@ -187,6 +189,93 @@ void ExtensionServiceTestBase::ResetThreadBundle(int options) {
thread_bundle_.reset(new content::TestBrowserThreadBundle(options));
}
size_t ExtensionServiceTestBase::GetPrefKeyCount() {
const base::DictionaryValue* dict =
profile()->GetPrefs()->GetDictionary("extensions.settings");
if (!dict) {
ADD_FAILURE();
return 0;
}
return dict->size();
}
void ExtensionServiceTestBase::ValidatePrefKeyCount(size_t count) {
EXPECT_EQ(count, GetPrefKeyCount());
}
testing::AssertionResult ExtensionServiceTestBase::ValidateBooleanPref(
const std::string& extension_id,
const std::string& pref_path,
bool expected_val) {
std::string msg = base::StringPrintf("while checking: %s %s == %s",
extension_id.c_str(), pref_path.c_str(),
expected_val ? "true" : "false");
PrefService* prefs = profile()->GetPrefs();
const base::DictionaryValue* dict =
prefs->GetDictionary("extensions.settings");
if (!dict) {
return testing::AssertionFailure()
<< "extension.settings does not exist " << msg;
}
const base::DictionaryValue* pref = NULL;
if (!dict->GetDictionary(extension_id, &pref)) {
return testing::AssertionFailure()
<< "extension pref does not exist " << msg;
}
bool val = false;
if (!pref->GetBoolean(pref_path, &val)) {
return testing::AssertionFailure()
<< pref_path << " pref not found " << msg;
}
return expected_val == val
? testing::AssertionSuccess()
: testing::AssertionFailure() << "base::Value is incorrect " << msg;
}
void ExtensionServiceTestBase::ValidateIntegerPref(
const std::string& extension_id,
const std::string& pref_path,
int expected_val) {
std::string msg = base::StringPrintf("while checking: %s %s == %s",
extension_id.c_str(), pref_path.c_str(),
base::IntToString(expected_val).c_str());
PrefService* prefs = profile()->GetPrefs();
const base::DictionaryValue* dict =
prefs->GetDictionary("extensions.settings");
ASSERT_TRUE(dict != NULL) << msg;
const base::DictionaryValue* pref = NULL;
ASSERT_TRUE(dict->GetDictionary(extension_id, &pref)) << msg;
EXPECT_TRUE(pref != NULL) << msg;
int val;
ASSERT_TRUE(pref->GetInteger(pref_path, &val)) << msg;
EXPECT_EQ(expected_val, val) << msg;
}
void ExtensionServiceTestBase::ValidateStringPref(
const std::string& extension_id,
const std::string& pref_path,
const std::string& expected_val) {
std::string msg = base::StringPrintf("while checking: %s.manifest.%s == %s",
extension_id.c_str(), pref_path.c_str(),
expected_val.c_str());
const base::DictionaryValue* dict =
profile()->GetPrefs()->GetDictionary("extensions.settings");
ASSERT_TRUE(dict != NULL) << msg;
const base::DictionaryValue* pref = NULL;
std::string manifest_path = extension_id + ".manifest";
ASSERT_TRUE(dict->GetDictionary(manifest_path, &pref)) << msg;
EXPECT_TRUE(pref != NULL) << msg;
std::string val;
ASSERT_TRUE(pref->GetString(pref_path, &val)) << msg;
EXPECT_EQ(expected_val, val) << msg;
}
void ExtensionServiceTestBase::SetUp() {
ExtensionErrorReporter::GetInstance()->ClearErrors();
}
......
......@@ -5,9 +5,12 @@
#ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_SERVICE_TEST_BASE_H_
#define CHROME_BROWSER_EXTENSIONS_EXTENSION_SERVICE_TEST_BASE_H_
#include <string>
#include "base/at_exit.h"
#include "base/files/file_path.h"
#include "base/files/scoped_temp_dir.h"
#include "base/macros.h"
#include "base/memory/scoped_ptr.h"
#include "chrome/test/base/scoped_testing_local_state.h"
#include "content/public/test/test_browser_thread_bundle.h"
......@@ -89,6 +92,20 @@ class ExtensionServiceTestBase : public testing::Test {
// Resets the browser thread bundle to one with |options|.
void ResetThreadBundle(int options);
// Helpers to check the existence and values of extension prefs.
size_t GetPrefKeyCount();
void ValidatePrefKeyCount(size_t count);
testing::AssertionResult ValidateBooleanPref(
const std::string& extension_id,
const std::string& pref_path,
bool expected_val);
void ValidateIntegerPref(const std::string& extension_id,
const std::string& pref_path,
int expected_val);
void ValidateStringPref(const std::string& extension_id,
const std::string& pref_path,
const std::string& expected_val);
// TODO(rdevlin.cronin): Pull out more methods from ExtensionServiceTest that
// are commonly used and/or reimplemented. For instance, methods to install
// extensions from various locations, etc.
......@@ -148,6 +165,8 @@ class ExtensionServiceTestBase : public testing::Test {
chromeos::ScopedTestCrosSettings test_cros_settings_;
chromeos::ScopedTestUserManager test_user_manager_;
#endif
DISALLOW_COPY_AND_ASSIGN(ExtensionServiceTestBase);
};
} // namespace extensions
......
// Copyright 2015 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.
#ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_SERVICE_TEST_WITH_INSTALL_H_
#define CHROME_BROWSER_EXTENSIONS_EXTENSION_SERVICE_TEST_WITH_INSTALL_H_
#include <string>
#include "base/files/file_path.h"
#include "base/macros.h"
#include "chrome/browser/extensions/extension_service_test_base.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"
#include "extensions/common/extension.h"
#include "extensions/common/feature_switch.h"
namespace extensions {
// An enhancement of ExtensionServiceTestBase that provides helpers to install,
// update, and uninstall extensions.
class ExtensionServiceTestWithInstall : public ExtensionServiceTestBase,
public content::NotificationObserver {
public:
ExtensionServiceTestWithInstall();
~ExtensionServiceTestWithInstall() override;
protected:
static std::vector<base::string16> GetErrors();
void PackCRX(const base::FilePath& dir_path,
const base::FilePath& pem_path,
const base::FilePath& crx_path);
enum InstallState {
INSTALL_FAILED,
INSTALL_UPDATED,
INSTALL_NEW,
INSTALL_WITHOUT_LOAD,
};
const Extension* PackAndInstallCRX(const base::FilePath& dir_path,
const base::FilePath& pem_path,
InstallState install_state,
int creation_flags);
const Extension* PackAndInstallCRX(const base::FilePath& dir_path,
const base::FilePath& pem_path,
InstallState install_state);
const Extension* PackAndInstallCRX(const base::FilePath& dir_path,
InstallState install_state);
const Extension* InstallCRX(const base::FilePath& path,
InstallState install_state,
int creation_flags,
const std::string& expected_old_name);
const Extension* InstallCRX(const base::FilePath& path,
InstallState install_state,
int creation_flags);
const Extension* InstallCRX(const base::FilePath& path,
InstallState install_state);
const Extension* InstallCRXFromWebStore(const base::FilePath& path,
InstallState install_state);
const Extension* InstallCRXWithLocation(const base::FilePath& crx_path,
Manifest::Location install_location,
InstallState install_state);
// Verifies the result of a CRX installation. Used by InstallCRX. Set the
// |install_state| to INSTALL_FAILED if the installation is expected to fail.
// Returns an Extension pointer if the install succeeded, null otherwise.
const Extension* VerifyCrxInstall(const base::FilePath& path,
InstallState install_state);
// Verifies the result of a CRX installation. Used by InstallCRX. Set the
// |install_state| to INSTALL_FAILED if the installation is expected to fail.
// If |install_state| is INSTALL_UPDATED, and |expected_old_name| is
// non-empty, expects that the existing extension's title was
// |expected_old_name|.
// Returns an Extension pointer if the install succeeded, null otherwise.
const Extension* VerifyCrxInstall(const base::FilePath& path,
InstallState install_state,
const std::string& expected_old_name);
enum UpdateState {
FAILED_SILENTLY,
FAILED,
UPDATED,
INSTALLED,
DISABLED,
ENABLED
};
void PackCRXAndUpdateExtension(const std::string& id,
const base::FilePath& dir_path,
const base::FilePath& pem_path,
UpdateState expected_state);
void UpdateExtension(const std::string& id,
const base::FilePath& in_path,
UpdateState expected_state);
void UninstallExtension(const std::string& id, bool use_helper);
void UninstallExtension(const std::string& id,
bool use_helper,
Extension::State expected_state);
void TerminateExtension(const std::string& id);
// TODO(treib,devlin): Make these private and add accessors as needed.
extensions::ExtensionList loaded_;
const Extension* installed_;
bool was_update_;
std::string old_name_;
std::string unloaded_id_;
UnloadedExtensionInfo::Reason unloaded_reason_;
private:
void Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) override;
void InstallCRXInternal(const base::FilePath& crx_path, int creation_flags);
content::NotificationRegistrar registrar_;
size_t expected_extensions_count_;
FeatureSwitch::ScopedOverride override_external_install_prompt_;
DISALLOW_COPY_AND_ASSIGN(ExtensionServiceTestWithInstall);
};
} // namespace extensions
#endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_SERVICE_TEST_WITH_INSTALL_H_
......@@ -693,8 +693,11 @@
'browser/extensions/extension_prefs_unittest.h',
'browser/extensions/extension_protocols_unittest.cc',
'browser/extensions/extension_reenabler_unittest.cc',
'browser/extensions/extension_service_sync_unittest.cc',
'browser/extensions/extension_service_test_base.cc',
'browser/extensions/extension_service_test_base.h',
'browser/extensions/extension_service_test_with_install.cc',
'browser/extensions/extension_service_test_with_install.h',
'browser/extensions/extension_service_unittest.cc',
'browser/extensions/extension_special_storage_policy_unittest.cc',
'browser/extensions/extension_sync_data_unittest.cc',
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment