| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 <map> | 5 #include <map> |
| 6 | 6 |
| 7 #include "base/registry.h" | 7 #include "base/registry.h" |
| 8 #include "chrome/browser/browser_process.h" | 8 #include "chrome/browser/browser_process.h" |
| 9 #include "chrome/browser/extensions/extension_function.h" |
| 10 #include "chrome/browser/extensions/extension_function_dispatcher.h" |
| 9 #include "chrome/browser/extensions/extension_apitest.h" | 11 #include "chrome/browser/extensions/extension_apitest.h" |
| 12 #include "chrome/browser/extensions/extension_rlz_module.h" |
| 10 #include "chrome/common/chrome_switches.h" | 13 #include "chrome/common/chrome_switches.h" |
| 11 #include "chrome/common/extensions/extension.h" | 14 #include "chrome/common/extensions/extension.h" |
| 12 #include "rlz/win/lib/rlz_lib.h" | 15 #include "rlz/win/lib/rlz_lib.h" |
| 13 | 16 |
| 17 class MockRlzSendFinancialPingFunction : public RlzSendFinancialPingFunction { |
| 18 virtual bool RunImpl(); |
| 19 |
| 20 static int expected_count_; |
| 21 |
| 22 public: |
| 23 static int expected_count() { |
| 24 return expected_count_; |
| 25 } |
| 26 }; |
| 27 |
| 28 int MockRlzSendFinancialPingFunction::expected_count_ = 0; |
| 29 |
| 30 bool MockRlzSendFinancialPingFunction::RunImpl() { |
| 31 EXPECT_TRUE(RlzSendFinancialPingFunction::RunImpl()); |
| 32 ++expected_count_; |
| 33 return true; |
| 34 } |
| 35 |
| 36 ExtensionFunction* MockRlzSendFinancialPingFunctionFactory() { |
| 37 return new MockRlzSendFinancialPingFunction(); |
| 38 } |
| 39 |
| 14 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, Rlz) { | 40 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, Rlz) { |
| 15 CommandLine::ForCurrentProcess()->AppendSwitch( | 41 CommandLine::ForCurrentProcess()->AppendSwitch( |
| 16 switches::kEnableExperimentalExtensionApis); | 42 switches::kEnableExperimentalExtensionApis); |
| 17 | 43 |
| 18 // Before running the tests, clear the state of the RLZ products used. | 44 // Before running the tests, clear the state of the RLZ products used. |
| 19 rlz_lib::AccessPoint access_points[] = { | 45 rlz_lib::AccessPoint access_points[] = { |
| 20 rlz_lib::GD_WEB_SERVER, | 46 rlz_lib::GD_WEB_SERVER, |
| 21 rlz_lib::GD_OUTLOOK, | 47 rlz_lib::GD_OUTLOOK, |
| 22 rlz_lib::NO_ACCESS_POINT, | 48 rlz_lib::NO_ACCESS_POINT, |
| 23 }; | 49 }; |
| 24 rlz_lib::ClearProductState(rlz_lib::PINYIN_IME, access_points); | 50 rlz_lib::ClearProductState(rlz_lib::PINYIN_IME, access_points); |
| 25 rlz_lib::ClearProductState(rlz_lib::DESKTOP, access_points); | 51 rlz_lib::ClearProductState(rlz_lib::DESKTOP, access_points); |
| 26 | 52 |
| 27 // Check that the state has really been cleared. | 53 // Check that the state has really been cleared. |
| 28 RegKey key(HKEY_CURRENT_USER, L"Software\\Google\\Common\\Rlz\\Events\\N"); | 54 RegKey key(HKEY_CURRENT_USER, L"Software\\Google\\Common\\Rlz\\Events\\N"); |
| 29 ASSERT_FALSE(key.Valid()); | 55 ASSERT_FALSE(key.Valid()); |
| 30 | 56 |
| 57 // Mock out experimental.rlz.sendFinancialPing(). |
| 58 ASSERT_TRUE(ExtensionFunctionDispatcher::OverrideFunction( |
| 59 "experimental.rlz.sendFinancialPing", |
| 60 MockRlzSendFinancialPingFunctionFactory)); |
| 61 |
| 31 // Set the access point that the test code is expecting. | 62 // Set the access point that the test code is expecting. |
| 32 ASSERT_TRUE(rlz_lib::SetAccessPointRlz(rlz_lib::GD_DESKBAND, "rlz_apitest")); | 63 ASSERT_TRUE(rlz_lib::SetAccessPointRlz(rlz_lib::GD_DESKBAND, "rlz_apitest")); |
| 33 | 64 |
| 34 // Now run all the tests. | 65 // Now run all the tests. |
| 35 ASSERT_TRUE(RunExtensionTest("rlz")) << message_; | 66 ASSERT_TRUE(RunExtensionTest("rlz")) << message_; |
| 36 | 67 |
| 68 ASSERT_EQ(1, MockRlzSendFinancialPingFunction::expected_count()); |
| 69 ExtensionFunctionDispatcher::ResetFunctions(); |
| 70 |
| 37 // Now make sure we recorded what was expected. If the code in test.js | 71 // Now make sure we recorded what was expected. If the code in test.js |
| 38 // changes, need to make appropriate changes here. | 72 // changes, need to make appropriate changes here. |
| 39 key.Open(HKEY_CURRENT_USER, L"Software\\Google\\Common\\Rlz\\Events\\N"); | 73 key.Open(HKEY_CURRENT_USER, L"Software\\Google\\Common\\Rlz\\Events\\N"); |
| 40 ASSERT_TRUE(key.Valid()); | 74 ASSERT_TRUE(key.Valid()); |
| 41 | 75 |
| 42 DWORD value; | 76 DWORD value; |
| 43 ASSERT_TRUE(key.ReadValueDW(L"D3I", &value)); | 77 ASSERT_TRUE(key.ReadValueDW(L"D3I", &value)); |
| 44 ASSERT_EQ(1, value); | 78 ASSERT_EQ(1, value); |
| 45 ASSERT_TRUE(key.ReadValueDW(L"D3S", &value)); | 79 ASSERT_TRUE(key.ReadValueDW(L"D3S", &value)); |
| 46 ASSERT_EQ(1, value); | 80 ASSERT_EQ(1, value); |
| 47 ASSERT_TRUE(key.ReadValueDW(L"D3F", &value)); | 81 ASSERT_TRUE(key.ReadValueDW(L"D3F", &value)); |
| 48 ASSERT_EQ(1, value); | 82 ASSERT_EQ(1, value); |
| 49 | 83 |
| 50 ASSERT_TRUE(key.ReadValueDW(L"D4I", &value)); | 84 ASSERT_TRUE(key.ReadValueDW(L"D4I", &value)); |
| 51 ASSERT_EQ(1, value); | 85 ASSERT_EQ(1, value); |
| 52 | 86 |
| 53 key.Open(HKEY_CURRENT_USER, L"Software\\Google\\Common\\Rlz\\Events\\D"); | 87 key.Open(HKEY_CURRENT_USER, L"Software\\Google\\Common\\Rlz\\Events\\D"); |
| 54 ASSERT_FALSE(key.Valid()); | 88 ASSERT_FALSE(key.Valid()); |
| 55 | 89 |
| 56 // Cleanup. | 90 // Cleanup. |
| 57 rlz_lib::ClearProductState(rlz_lib::PINYIN_IME, access_points); | 91 rlz_lib::ClearProductState(rlz_lib::PINYIN_IME, access_points); |
| 58 } | 92 } |
| OLD | NEW |