This source file includes following definitions.
- SetUp
- GetBlacklistState
- GetBlacklistVersion
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
#include "chrome/browser/chrome_elf_init_win.h"
#include "base/basictypes.h"
#include "base/memory/scoped_ptr.h"
#include "base/strings/string16.h"
#include "base/strings/utf_string_conversions.h"
#include "base/test/test_reg_util_win.h"
#include "chrome/common/chrome_version_info.h"
#include "chrome_elf/chrome_elf_constants.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "version.h"
class ChromeBlacklistTrialTest : public testing::Test {
protected:
ChromeBlacklistTrialTest() {}
virtual ~ChromeBlacklistTrialTest() {}
virtual void SetUp() OVERRIDE {
testing::Test::SetUp();
override_manager_.OverrideRegistry(HKEY_CURRENT_USER,
L"browser_blacklist_test");
blacklist_registry_key_.reset(
new base::win::RegKey(HKEY_CURRENT_USER,
blacklist::kRegistryBeaconPath,
KEY_QUERY_VALUE | KEY_SET_VALUE));
}
DWORD GetBlacklistState() {
DWORD blacklist_state = blacklist::BLACKLIST_STATE_MAX;
blacklist_registry_key_->ReadValueDW(blacklist::kBeaconState,
&blacklist_state);
return blacklist_state;
}
base::string16 GetBlacklistVersion() {
base::string16 blacklist_version;
blacklist_registry_key_->ReadValue(blacklist::kBeaconVersion,
&blacklist_version);
return blacklist_version;
}
scoped_ptr<base::win::RegKey> blacklist_registry_key_;
registry_util::RegistryOverrideManager override_manager_;
private:
DISALLOW_COPY_AND_ASSIGN(ChromeBlacklistTrialTest);
};
TEST_F(ChromeBlacklistTrialTest, DefaultRun) {
blacklist_registry_key_->WriteValue(blacklist::kBeaconState,
blacklist::BLACKLIST_ENABLED);
blacklist_registry_key_->WriteValue(blacklist::kBeaconVersion, L"Data");
InitializeChromeElf();
ASSERT_EQ(blacklist::BLACKLIST_STATE_MAX, GetBlacklistState());
ASSERT_EQ(base::string16(), GetBlacklistVersion());
}
TEST_F(ChromeBlacklistTrialTest, VerifyFirstRun) {
BrowserBlacklistBeaconSetup();
ASSERT_EQ(blacklist::BLACKLIST_ENABLED, GetBlacklistState());
chrome::VersionInfo version_info;
base::string16 version(base::UTF8ToUTF16(version_info.Version()));
ASSERT_EQ(version, GetBlacklistVersion());
}
TEST_F(ChromeBlacklistTrialTest, SetupFailed) {
blacklist_registry_key_->WriteValue(blacklist::kBeaconVersion,
TEXT(CHROME_VERSION_STRING));
blacklist_registry_key_->WriteValue(blacklist::kBeaconState,
blacklist::BLACKLIST_SETUP_RUNNING);
BrowserBlacklistBeaconSetup();
ASSERT_EQ(blacklist::BLACKLIST_DISABLED, GetBlacklistState());
}
TEST_F(ChromeBlacklistTrialTest, ThunkSetupFailed) {
blacklist_registry_key_->WriteValue(blacklist::kBeaconVersion,
TEXT(CHROME_VERSION_STRING));
blacklist_registry_key_->WriteValue(blacklist::kBeaconState,
blacklist::BLACKLIST_THUNK_SETUP);
BrowserBlacklistBeaconSetup();
ASSERT_EQ(blacklist::BLACKLIST_DISABLED, GetBlacklistState());
}
TEST_F(ChromeBlacklistTrialTest, InterceptionFailed) {
blacklist_registry_key_->WriteValue(blacklist::kBeaconVersion,
TEXT(CHROME_VERSION_STRING));
blacklist_registry_key_->WriteValue(blacklist::kBeaconState,
blacklist::BLACKLIST_INTERCEPTING);
BrowserBlacklistBeaconSetup();
ASSERT_EQ(blacklist::BLACKLIST_DISABLED, GetBlacklistState());
}
TEST_F(ChromeBlacklistTrialTest, VersionChanged) {
blacklist_registry_key_->WriteValue(blacklist::kBeaconVersion,
L"old_version");
blacklist_registry_key_->WriteValue(blacklist::kBeaconState,
blacklist::BLACKLIST_DISABLED);
BrowserBlacklistBeaconSetup();
ASSERT_EQ(blacklist::BLACKLIST_ENABLED, GetBlacklistState());
chrome::VersionInfo version_info;
base::string16 expected_version(base::UTF8ToUTF16(version_info.Version()));
ASSERT_EQ(expected_version, GetBlacklistVersion());
}