| OLD | NEW |
| 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/rlz/rlz.h" | 5 #include "chrome/browser/rlz/rlz.h" |
| 6 | 6 |
| 7 #include "base/files/scoped_temp_dir.h" | 7 #include "base/files/scoped_temp_dir.h" |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
| 10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 #include "content/public/browser/navigation_entry.h" | 21 #include "content/public/browser/navigation_entry.h" |
| 22 #include "content/public/browser/notification_details.h" | 22 #include "content/public/browser/notification_details.h" |
| 23 #include "content/public/browser/notification_service.h" | 23 #include "content/public/browser/notification_service.h" |
| 24 #include "content/public/browser/notification_source.h" | 24 #include "content/public/browser/notification_source.h" |
| 25 #include "testing/gtest/include/gtest/gtest.h" | 25 #include "testing/gtest/include/gtest/gtest.h" |
| 26 | 26 |
| 27 #if defined(OS_WIN) | 27 #if defined(OS_WIN) |
| 28 #include "base/test/test_reg_util_win.h" | 28 #include "base/test/test_reg_util_win.h" |
| 29 #include "base/win/registry.h" | 29 #include "base/win/registry.h" |
| 30 #include "rlz/win/lib/rlz_lib.h" // InitializeTempHivesForTesting | 30 #include "rlz/win/lib/rlz_lib.h" // InitializeTempHivesForTesting |
| 31 #elif defined(OS_MACOSX) || defined(OS_CHROMEOS) | 31 #elif defined(OS_POSIX) |
| 32 #include "rlz/lib/rlz_value_store.h" // SetRlzStoreDirectory | 32 #include "rlz/lib/rlz_value_store.h" // SetRlzStoreDirectory |
| 33 #endif | 33 #endif |
| 34 #if defined(OS_CHROMEOS) | |
| 35 #include "rlz/chromeos/lib/rlz_value_store_chromeos.h" | |
| 36 #endif | |
| 37 | 34 |
| 38 using content::NavigationEntry; | 35 using content::NavigationEntry; |
| 39 using testing::AssertionResult; | 36 using testing::AssertionResult; |
| 40 using testing::AssertionSuccess; | 37 using testing::AssertionSuccess; |
| 41 using testing::AssertionFailure; | 38 using testing::AssertionFailure; |
| 42 | 39 |
| 43 #if defined(OS_WIN) | 40 #if defined(OS_WIN) |
| 44 using base::win::RegKey; | 41 using base::win::RegKey; |
| 45 using registry_util::RegistryOverrideManager; | 42 using registry_util::RegistryOverrideManager; |
| 46 #endif | 43 #endif |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 } | 162 } |
| 166 | 163 |
| 167 std::set<std::string> pinged_brands_; | 164 std::set<std::string> pinged_brands_; |
| 168 bool assume_not_ui_thread_; | 165 bool assume_not_ui_thread_; |
| 169 | 166 |
| 170 DISALLOW_COPY_AND_ASSIGN(TestRLZTracker); | 167 DISALLOW_COPY_AND_ASSIGN(TestRLZTracker); |
| 171 }; | 168 }; |
| 172 | 169 |
| 173 class RlzLibTest : public testing::Test { | 170 class RlzLibTest : public testing::Test { |
| 174 public: | 171 public: |
| 175 #if defined(OS_CHROMEOS) | |
| 176 RlzLibTest(); | |
| 177 #endif | |
| 178 | |
| 179 virtual void SetUp() OVERRIDE; | 172 virtual void SetUp() OVERRIDE; |
| 180 virtual void TearDown() OVERRIDE; | 173 virtual void TearDown() OVERRIDE; |
| 181 | 174 |
| 182 protected: | 175 protected: |
| 183 void SetMainBrand(const char* brand); | 176 void SetMainBrand(const char* brand); |
| 184 void SetReactivationBrand(const char* brand); | 177 void SetReactivationBrand(const char* brand); |
| 185 #if defined(OS_WIN) | 178 #if defined(OS_WIN) |
| 186 void SetRegistryBrandValue(const wchar_t* name, const char* brand); | 179 void SetRegistryBrandValue(const wchar_t* name, const char* brand); |
| 187 #endif | 180 #endif |
| 188 | 181 |
| 189 void SimulateOmniboxUsage(); | 182 void SimulateOmniboxUsage(); |
| 190 void SimulateHomepageUsage(); | 183 void SimulateHomepageUsage(); |
| 191 void InvokeDelayedInit(); | 184 void InvokeDelayedInit(); |
| 192 | 185 |
| 193 void ExpectEventRecorded(const char* event_name, bool expected); | 186 void ExpectEventRecorded(const char* event_name, bool expected); |
| 194 void ExpectRlzPingSent(bool expected); | 187 void ExpectRlzPingSent(bool expected); |
| 195 void ExpectReactivationRlzPingSent(bool expected); | 188 void ExpectReactivationRlzPingSent(bool expected); |
| 196 | 189 |
| 197 TestRLZTracker tracker_; | 190 TestRLZTracker tracker_; |
| 198 #if defined(OS_WIN) | 191 #if defined(OS_WIN) |
| 199 RegistryOverrideManager override_manager_; | 192 RegistryOverrideManager override_manager_; |
| 200 #elif defined(OS_MACOSX) || defined(OS_CHROMEOS) | 193 #elif defined(OS_POSIX) |
| 201 base::ScopedTempDir temp_dir_; | 194 base::ScopedTempDir temp_dir_; |
| 202 scoped_ptr<google_util::BrandForTesting> brand_override_; | 195 scoped_ptr<google_util::BrandForTesting> brand_override_; |
| 203 #endif | 196 #endif |
| 204 #if defined(OS_CHROMEOS) | |
| 205 MessageLoop loop_; | |
| 206 base::Thread io_thread_; | |
| 207 #endif | |
| 208 }; | 197 }; |
| 209 | 198 |
| 210 #if defined(OS_CHROMEOS) | |
| 211 RlzLibTest::RlzLibTest() | |
| 212 : io_thread_("RlzLibTest-io") { | |
| 213 } | |
| 214 #endif | |
| 215 | |
| 216 void RlzLibTest::SetUp() { | 199 void RlzLibTest::SetUp() { |
| 217 testing::Test::SetUp(); | 200 testing::Test::SetUp(); |
| 218 | 201 |
| 219 #if defined(OS_WIN) | 202 #if defined(OS_WIN) |
| 220 // Before overriding HKLM for the tests, we need to set it up correctly | 203 // Before overriding HKLM for the tests, we need to set it up correctly |
| 221 // so that the rlz_lib calls work. This needs to be done before we do the | 204 // so that the rlz_lib calls work. This needs to be done before we do the |
| 222 // override. | 205 // override. |
| 223 | 206 |
| 224 string16 temp_hklm_path = base::StringPrintf( | 207 string16 temp_hklm_path = base::StringPrintf( |
| 225 L"%ls\\%ls", | 208 L"%ls\\%ls", |
| (...skipping 14 matching lines...) Expand all Loading... |
| 240 ASSERT_EQ(ERROR_SUCCESS, hkcu.Create(HKEY_CURRENT_USER, | 223 ASSERT_EQ(ERROR_SUCCESS, hkcu.Create(HKEY_CURRENT_USER, |
| 241 temp_hkcu_path.c_str(), | 224 temp_hkcu_path.c_str(), |
| 242 KEY_READ)); | 225 KEY_READ)); |
| 243 | 226 |
| 244 rlz_lib::InitializeTempHivesForTesting(hklm, hkcu); | 227 rlz_lib::InitializeTempHivesForTesting(hklm, hkcu); |
| 245 | 228 |
| 246 // Its important to override HKLM before HKCU because of the registry | 229 // Its important to override HKLM before HKCU because of the registry |
| 247 // initialization performed above. | 230 // initialization performed above. |
| 248 override_manager_.OverrideRegistry(HKEY_LOCAL_MACHINE, kRlzTempHklm); | 231 override_manager_.OverrideRegistry(HKEY_LOCAL_MACHINE, kRlzTempHklm); |
| 249 override_manager_.OverrideRegistry(HKEY_CURRENT_USER, kRlzTempHkcu); | 232 override_manager_.OverrideRegistry(HKEY_CURRENT_USER, kRlzTempHkcu); |
| 250 #elif defined(OS_MACOSX) || defined(OS_CHROMEOS) | 233 #elif defined(OS_POSIX) |
| 251 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 234 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
| 252 rlz_lib::testing::SetRlzStoreDirectory(temp_dir_.path()); | 235 rlz_lib::testing::SetRlzStoreDirectory(temp_dir_.path()); |
| 253 #endif | 236 #endif |
| 254 | 237 |
| 255 #if defined(OS_CHROMEOS) | |
| 256 base::Thread::Options options; | |
| 257 options.message_loop_type = MessageLoop::TYPE_IO; | |
| 258 ASSERT_TRUE(io_thread_.StartWithOptions(options)); | |
| 259 rlz_lib::SetIOTaskRunner(io_thread_.message_loop_proxy()); | |
| 260 rlz_lib::RlzValueStoreChromeOS::ResetForTesting(); | |
| 261 #endif | |
| 262 | |
| 263 // Make sure a non-organic brand code is set in the registry or the RLZTracker | 238 // Make sure a non-organic brand code is set in the registry or the RLZTracker |
| 264 // is pretty much a no-op. | 239 // is pretty much a no-op. |
| 265 SetMainBrand("TEST"); | 240 SetMainBrand("TEST"); |
| 266 SetReactivationBrand(""); | 241 SetReactivationBrand(""); |
| 267 } | 242 } |
| 268 | 243 |
| 269 void RlzLibTest::TearDown() { | 244 void RlzLibTest::TearDown() { |
| 270 #if defined(OS_MACOSX) || defined(OS_CHROMEOS) | 245 #if defined(OS_POSIX) |
| 271 rlz_lib::testing::SetRlzStoreDirectory(FilePath()); | 246 rlz_lib::testing::SetRlzStoreDirectory(FilePath()); |
| 272 #endif | 247 #endif |
| 273 #if defined(OS_CHROMEOS) | |
| 274 io_thread_.Stop(); | |
| 275 #endif // defined(OS_CHROMEOS) | |
| 276 testing::Test::TearDown(); | 248 testing::Test::TearDown(); |
| 277 } | 249 } |
| 278 | 250 |
| 279 void RlzLibTest::SetMainBrand(const char* brand) { | 251 void RlzLibTest::SetMainBrand(const char* brand) { |
| 280 #if defined(OS_WIN) | 252 #if defined(OS_WIN) |
| 281 SetRegistryBrandValue(google_update::kRegRLZBrandField, brand); | 253 SetRegistryBrandValue(google_update::kRegRLZBrandField, brand); |
| 282 #elif defined(OS_MACOSX) || defined(OS_CHROMEOS) | 254 #elif defined(OS_POSIX) |
| 283 brand_override_.reset(new google_util::BrandForTesting(brand)); | 255 brand_override_.reset(new google_util::BrandForTesting(brand)); |
| 284 #endif | 256 #endif |
| 285 std::string check_brand; | 257 std::string check_brand; |
| 286 google_util::GetBrand(&check_brand); | 258 google_util::GetBrand(&check_brand); |
| 287 EXPECT_EQ(brand, check_brand); | 259 EXPECT_EQ(brand, check_brand); |
| 288 } | 260 } |
| 289 | 261 |
| 290 void RlzLibTest::SetReactivationBrand(const char* brand) { | 262 void RlzLibTest::SetReactivationBrand(const char* brand) { |
| 291 // TODO(thakis): Reactivation doesn't exist on Mac yet. | 263 // TODO(thakis): Reactivation doesn't exist on Mac yet. |
| 292 #if defined(OS_WIN) | 264 #if defined(OS_WIN) |
| (...skipping 503 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 796 SetMainBrand("GGLS"); | 768 SetMainBrand("GGLS"); |
| 797 SetReactivationBrand("GGRS"); | 769 SetReactivationBrand("GGRS"); |
| 798 | 770 |
| 799 RLZTracker::InitRlzDelayed(true, 20, true, true, false); | 771 RLZTracker::InitRlzDelayed(true, 20, true, true, false); |
| 800 InvokeDelayedInit(); | 772 InvokeDelayedInit(); |
| 801 | 773 |
| 802 ExpectRlzPingSent(false); | 774 ExpectRlzPingSent(false); |
| 803 ExpectReactivationRlzPingSent(false); | 775 ExpectReactivationRlzPingSent(false); |
| 804 } | 776 } |
| 805 #endif // defined(OS_WIN) | 777 #endif // defined(OS_WIN) |
| OLD | NEW |