Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(774)

Side by Side Diff: chrome/browser/rlz/rlz_extension_apitest.cc

Issue 9699054: rlz: Hook up on mac, switch to chrome's network stack on win. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/win/registry.h" 7 #include "chrome/browser/browser_process.h"
8 #include "chrome/browser/extensions/extension_function.h" 8 #include "chrome/browser/extensions/extension_function.h"
9 #include "chrome/browser/extensions/extension_function_dispatcher.h" 9 #include "chrome/browser/extensions/extension_function_dispatcher.h"
10 #include "chrome/browser/extensions/extension_apitest.h" 10 #include "chrome/browser/extensions/extension_apitest.h"
11 #include "chrome/browser/rlz/rlz_extension_api.h" 11 #include "chrome/browser/rlz/rlz_extension_api.h"
12 #include "chrome/common/chrome_switches.h" 12 #include "chrome/common/chrome_switches.h"
13 #include "chrome/common/extensions/extension.h" 13 #include "chrome/common/extensions/extension.h"
14 #include "rlz/win/lib/rlz_lib.h" 14 #include "net/base/mock_host_resolver.h"
15 #include "rlz/lib/rlz_lib.h"
16
17 #if (OS_WIN)
18 #include "base/win/registry.h"
19 #endif
15 20
16 class MockRlzSendFinancialPingFunction : public RlzSendFinancialPingFunction { 21 class MockRlzSendFinancialPingFunction : public RlzSendFinancialPingFunction {
17 virtual bool RunImpl(); 22 virtual bool RunImpl();
18 23
19 static int expected_count_; 24 static int expected_count_;
20 25
21 public: 26 public:
22 static int expected_count() { 27 static int expected_count() {
23 return expected_count_; 28 return expected_count_;
24 } 29 }
25 }; 30 };
26 31
27 int MockRlzSendFinancialPingFunction::expected_count_ = 0; 32 int MockRlzSendFinancialPingFunction::expected_count_ = 0;
28 33
29 bool MockRlzSendFinancialPingFunction::RunImpl() { 34 bool MockRlzSendFinancialPingFunction::RunImpl() {
30 EXPECT_TRUE(RlzSendFinancialPingFunction::RunImpl()); 35 EXPECT_TRUE(RlzSendFinancialPingFunction::RunImpl());
31 ++expected_count_; 36 ++expected_count_;
32 return true; 37 return true;
33 } 38 }
34 39
35 ExtensionFunction* MockRlzSendFinancialPingFunctionFactory() { 40 ExtensionFunction* MockRlzSendFinancialPingFunctionFactory() {
36 return new MockRlzSendFinancialPingFunction(); 41 return new MockRlzSendFinancialPingFunction();
37 } 42 }
38 43
39 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, Rlz) { 44 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, Rlz) {
45 // The default test resolver doesn't allow lookups to *.google.com. That
46 // makes sense, but it does make RLZ's SendFinancialPing() fail -- so allow
47 // connections to google.com in this test.
48 scoped_refptr<net::RuleBasedHostResolverProc> resolver =
49 new net::RuleBasedHostResolverProc(host_resolver());
50 resolver->AllowDirectLookup("*.google.com");
51 net::ScopedDefaultHostResolverProc scoper(resolver);
52
40 CommandLine::ForCurrentProcess()->AppendSwitch( 53 CommandLine::ForCurrentProcess()->AppendSwitch(
41 switches::kEnableExperimentalExtensionApis); 54 switches::kEnableExperimentalExtensionApis);
42 55
43 // Before running the tests, clear the state of the RLZ products used. 56 // Before running the tests, clear the state of the RLZ products used.
44 rlz_lib::AccessPoint access_points[] = { 57 rlz_lib::AccessPoint access_points[] = {
45 rlz_lib::GD_WEB_SERVER, 58 rlz_lib::GD_WEB_SERVER,
46 rlz_lib::GD_OUTLOOK, 59 rlz_lib::GD_OUTLOOK,
47 rlz_lib::NO_ACCESS_POINT, 60 rlz_lib::NO_ACCESS_POINT,
48 }; 61 };
49 rlz_lib::ClearProductState(rlz_lib::PINYIN_IME, access_points); 62 rlz_lib::ClearProductState(rlz_lib::PINYIN_IME, access_points);
50 rlz_lib::ClearProductState(rlz_lib::DESKTOP, access_points); 63 rlz_lib::ClearProductState(rlz_lib::DESKTOP, access_points);
51 64
65 #if defined(OS_WIN)
52 // Check that the state has really been cleared. 66 // Check that the state has really been cleared.
53 base::win::RegKey key(HKEY_CURRENT_USER, 67 base::win::RegKey key(HKEY_CURRENT_USER,
54 L"Software\\Google\\Common\\Rlz\\Events\\N", 68 L"Software\\Google\\Common\\Rlz\\Events\\N",
55 KEY_READ); 69 KEY_READ);
56 ASSERT_FALSE(key.Valid()); 70 ASSERT_FALSE(key.Valid());
57 71
58 key.Open(HKEY_CURRENT_USER, L"Software\\Google\\Common\\Rlz\\Events\\D", 72 key.Open(HKEY_CURRENT_USER, L"Software\\Google\\Common\\Rlz\\Events\\D",
59 KEY_READ); 73 KEY_READ);
60 ASSERT_FALSE(key.Valid()); 74 ASSERT_FALSE(key.Valid());
75 #endif
61 76
62 // Mock out experimental.rlz.sendFinancialPing(). 77 // Mock out experimental.rlz.sendFinancialPing().
63 ASSERT_TRUE(ExtensionFunctionDispatcher::OverrideFunction( 78 ASSERT_TRUE(ExtensionFunctionDispatcher::OverrideFunction(
64 "experimental.rlz.sendFinancialPing", 79 "experimental.rlz.sendFinancialPing",
65 MockRlzSendFinancialPingFunctionFactory)); 80 MockRlzSendFinancialPingFunctionFactory));
66 81
67 // Set the access point that the test code is expecting. 82 // Set the access point that the test code is expecting.
68 ASSERT_TRUE(rlz_lib::SetAccessPointRlz(rlz_lib::GD_DESKBAND, "rlz_apitest")); 83 ASSERT_TRUE(rlz_lib::SetAccessPointRlz(rlz_lib::GD_DESKBAND, "rlz_apitest"));
69 84
70 // Now run all the tests. 85 // Now run all the tests.
71 ASSERT_TRUE(RunExtensionTest("rlz")) << message_; 86 ASSERT_TRUE(RunExtensionTest("rlz")) << message_;
72 87
73 ASSERT_EQ(3, MockRlzSendFinancialPingFunction::expected_count()); 88 ASSERT_EQ(3, MockRlzSendFinancialPingFunction::expected_count());
74 ExtensionFunctionDispatcher::ResetFunctions(); 89 ExtensionFunctionDispatcher::ResetFunctions();
75 90
91 #if defined(OS_WIN)
76 // Now make sure we recorded what was expected. If the code in test.js 92 // Now make sure we recorded what was expected. If the code in test.js
77 // changes, need to make appropriate changes here. 93 // changes, need to make appropriate changes here.
78 key.Open(HKEY_CURRENT_USER, L"Software\\Google\\Common\\Rlz\\Events\\N", 94 key.Open(HKEY_CURRENT_USER, L"Software\\Google\\Common\\Rlz\\Events\\N",
79 KEY_READ); 95 KEY_READ);
80 ASSERT_TRUE(key.Valid()); 96 ASSERT_TRUE(key.Valid());
81 97
82 DWORD value; 98 DWORD value;
83 ASSERT_EQ(ERROR_SUCCESS, key.ReadValueDW(L"D3I", &value)); 99 ASSERT_EQ(ERROR_SUCCESS, key.ReadValueDW(L"D3I", &value));
84 ASSERT_EQ(1, value); 100 ASSERT_EQ(1, value);
85 ASSERT_EQ(ERROR_SUCCESS, key.ReadValueDW(L"D3S", &value)); 101 ASSERT_EQ(ERROR_SUCCESS, key.ReadValueDW(L"D3S", &value));
86 ASSERT_EQ(1, value); 102 ASSERT_EQ(1, value);
87 ASSERT_EQ(ERROR_SUCCESS, key.ReadValueDW(L"D3F", &value)); 103 ASSERT_EQ(ERROR_SUCCESS, key.ReadValueDW(L"D3F", &value));
88 ASSERT_EQ(1, value); 104 ASSERT_EQ(1, value);
89 105
90 ASSERT_EQ(ERROR_SUCCESS, key.ReadValueDW(L"D4I", &value)); 106 ASSERT_EQ(ERROR_SUCCESS, key.ReadValueDW(L"D4I", &value));
91 ASSERT_EQ(1, value); 107 ASSERT_EQ(1, value);
92 108
93 key.Open(HKEY_CURRENT_USER, L"Software\\Google\\Common\\Rlz\\Events\\D", 109 key.Open(HKEY_CURRENT_USER, L"Software\\Google\\Common\\Rlz\\Events\\D",
94 KEY_READ); 110 KEY_READ);
95 ASSERT_FALSE(key.Valid()); 111 ASSERT_FALSE(key.Valid());
112 #endif
96 113
97 // Cleanup. 114 // Cleanup.
98 rlz_lib::ClearProductState(rlz_lib::PINYIN_IME, access_points); 115 rlz_lib::ClearProductState(rlz_lib::PINYIN_IME, access_points);
99 } 116 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698