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 // Unit tests for WebRequestEventsFunnel. | 5 // Unit tests for WebRequestEventsFunnel. |
6 | 6 |
7 #include <atlcomcli.h> | 7 #include <atlcomcli.h> |
8 | 8 |
9 #include "base/time.h" | 9 #include "base/time.h" |
10 #include "base/values.h" | 10 #include "base/values.h" |
(...skipping 25 matching lines...) Expand all Loading... |
36 std::wstring url(L"http://www.google.com/"); | 36 std::wstring url(L"http://www.google.com/"); |
37 DWORD status_code = 200; | 37 DWORD status_code = 200; |
38 std::wstring redirect_url(L"http://mail.google.com/"); | 38 std::wstring redirect_url(L"http://mail.google.com/"); |
39 base::Time time_stamp = base::Time::FromDoubleT(2048.0); | 39 base::Time time_stamp = base::Time::FromDoubleT(2048.0); |
40 | 40 |
41 DictionaryValue args; | 41 DictionaryValue args; |
42 args.SetInteger(keys::kRequestIdKey, request_id); | 42 args.SetInteger(keys::kRequestIdKey, request_id); |
43 args.SetString(keys::kUrlKey, url); | 43 args.SetString(keys::kUrlKey, url); |
44 args.SetInteger(keys::kStatusCodeKey, status_code); | 44 args.SetInteger(keys::kStatusCodeKey, status_code); |
45 args.SetString(keys::kRedirectUrlKey, redirect_url); | 45 args.SetString(keys::kRedirectUrlKey, redirect_url); |
46 args.SetReal(keys::kTimeStampKey, | 46 args.SetDouble(keys::kTimeStampKey, |
47 base::Time::kMillisecondsPerSecond * time_stamp.ToDoubleT()); | 47 base::Time::kMillisecondsPerSecond * time_stamp.ToDoubleT()); |
48 | 48 |
49 EXPECT_CALL(webrequest_events_funnel, | 49 EXPECT_CALL(webrequest_events_funnel, |
50 SendEvent(StrEq(keys::kOnBeforeRedirect), ValuesEqual(&args))) | 50 SendEvent(StrEq(keys::kOnBeforeRedirect), ValuesEqual(&args))) |
51 .WillOnce(Return(S_OK)); | 51 .WillOnce(Return(S_OK)); |
52 EXPECT_HRESULT_SUCCEEDED(webrequest_events_funnel.OnBeforeRedirect( | 52 EXPECT_HRESULT_SUCCEEDED(webrequest_events_funnel.OnBeforeRedirect( |
53 request_id, url.c_str(), status_code, redirect_url.c_str(), time_stamp)); | 53 request_id, url.c_str(), status_code, redirect_url.c_str(), time_stamp)); |
54 } | 54 } |
55 | 55 |
56 TEST(WebRequestEventsFunnelTest, OnBeforeRequest) { | 56 TEST(WebRequestEventsFunnelTest, OnBeforeRequest) { |
57 TestWebRequestEventsFunnel webrequest_events_funnel; | 57 TestWebRequestEventsFunnel webrequest_events_funnel; |
58 | 58 |
59 int request_id = 256; | 59 int request_id = 256; |
60 std::wstring url(L"http://calendar.google.com/"); | 60 std::wstring url(L"http://calendar.google.com/"); |
61 std::string method("GET"); | 61 std::string method("GET"); |
62 int tab_handle = 512; | 62 int tab_handle = 512; |
63 std::string type("main_frame"); | 63 std::string type("main_frame"); |
64 base::Time time_stamp = base::Time::FromDoubleT(2048.0); | 64 base::Time time_stamp = base::Time::FromDoubleT(2048.0); |
65 | 65 |
66 DictionaryValue args; | 66 DictionaryValue args; |
67 args.SetInteger(keys::kRequestIdKey, request_id); | 67 args.SetInteger(keys::kRequestIdKey, request_id); |
68 args.SetString(keys::kUrlKey, url); | 68 args.SetString(keys::kUrlKey, url); |
69 args.SetString(keys::kMethodKey, method); | 69 args.SetString(keys::kMethodKey, method); |
70 args.SetInteger(keys::kTabIdKey, tab_handle); | 70 args.SetInteger(keys::kTabIdKey, tab_handle); |
71 args.SetString(keys::kTypeKey, type); | 71 args.SetString(keys::kTypeKey, type); |
72 args.SetReal(keys::kTimeStampKey, | 72 args.SetDouble(keys::kTimeStampKey, |
73 base::Time::kMillisecondsPerSecond * time_stamp.ToDoubleT()); | 73 base::Time::kMillisecondsPerSecond * time_stamp.ToDoubleT()); |
74 | 74 |
75 EXPECT_CALL(webrequest_events_funnel, | 75 EXPECT_CALL(webrequest_events_funnel, |
76 SendEvent(StrEq(keys::kOnBeforeRequest), ValuesEqual(&args))) | 76 SendEvent(StrEq(keys::kOnBeforeRequest), ValuesEqual(&args))) |
77 .WillOnce(Return(S_OK)); | 77 .WillOnce(Return(S_OK)); |
78 EXPECT_HRESULT_SUCCEEDED(webrequest_events_funnel.OnBeforeRequest( | 78 EXPECT_HRESULT_SUCCEEDED(webrequest_events_funnel.OnBeforeRequest( |
79 request_id, url.c_str(), method.c_str(), | 79 request_id, url.c_str(), method.c_str(), |
80 static_cast<CeeeWindowHandle>(tab_handle), type.c_str(), time_stamp)); | 80 static_cast<CeeeWindowHandle>(tab_handle), type.c_str(), time_stamp)); |
81 } | 81 } |
82 | 82 |
83 TEST(WebRequestEventsFunnelTest, OnCompleted) { | 83 TEST(WebRequestEventsFunnelTest, OnCompleted) { |
84 TestWebRequestEventsFunnel webrequest_events_funnel; | 84 TestWebRequestEventsFunnel webrequest_events_funnel; |
85 | 85 |
86 int request_id = 256; | 86 int request_id = 256; |
87 std::wstring url(L"http://image.google.com/"); | 87 std::wstring url(L"http://image.google.com/"); |
88 DWORD status_code = 404; | 88 DWORD status_code = 404; |
89 base::Time time_stamp = base::Time::FromDoubleT(2048.0); | 89 base::Time time_stamp = base::Time::FromDoubleT(2048.0); |
90 | 90 |
91 DictionaryValue args; | 91 DictionaryValue args; |
92 args.SetInteger(keys::kRequestIdKey, request_id); | 92 args.SetInteger(keys::kRequestIdKey, request_id); |
93 args.SetString(keys::kUrlKey, url); | 93 args.SetString(keys::kUrlKey, url); |
94 args.SetInteger(keys::kStatusCodeKey, status_code); | 94 args.SetInteger(keys::kStatusCodeKey, status_code); |
95 args.SetReal(keys::kTimeStampKey, | 95 args.SetDouble(keys::kTimeStampKey, |
96 base::Time::kMillisecondsPerSecond * time_stamp.ToDoubleT()); | 96 base::Time::kMillisecondsPerSecond * time_stamp.ToDoubleT()); |
97 | 97 |
98 EXPECT_CALL(webrequest_events_funnel, | 98 EXPECT_CALL(webrequest_events_funnel, |
99 SendEvent(StrEq(keys::kOnCompleted), ValuesEqual(&args))) | 99 SendEvent(StrEq(keys::kOnCompleted), ValuesEqual(&args))) |
100 .WillOnce(Return(S_OK)); | 100 .WillOnce(Return(S_OK)); |
101 EXPECT_HRESULT_SUCCEEDED(webrequest_events_funnel.OnCompleted( | 101 EXPECT_HRESULT_SUCCEEDED(webrequest_events_funnel.OnCompleted( |
102 request_id, url.c_str(), status_code, time_stamp)); | 102 request_id, url.c_str(), status_code, time_stamp)); |
103 } | 103 } |
104 | 104 |
105 TEST(WebRequestEventsFunnelTest, OnErrorOccurred) { | 105 TEST(WebRequestEventsFunnelTest, OnErrorOccurred) { |
106 TestWebRequestEventsFunnel webrequest_events_funnel; | 106 TestWebRequestEventsFunnel webrequest_events_funnel; |
107 | 107 |
108 int request_id = 256; | 108 int request_id = 256; |
109 std::wstring url(L"http://docs.google.com/"); | 109 std::wstring url(L"http://docs.google.com/"); |
110 std::wstring error(L"cannot resolve the host"); | 110 std::wstring error(L"cannot resolve the host"); |
111 base::Time time_stamp = base::Time::FromDoubleT(2048.0); | 111 base::Time time_stamp = base::Time::FromDoubleT(2048.0); |
112 | 112 |
113 DictionaryValue args; | 113 DictionaryValue args; |
114 args.SetInteger(keys::kRequestIdKey, request_id); | 114 args.SetInteger(keys::kRequestIdKey, request_id); |
115 args.SetString(keys::kUrlKey, url); | 115 args.SetString(keys::kUrlKey, url); |
116 args.SetString(keys::kErrorKey, error); | 116 args.SetString(keys::kErrorKey, error); |
117 args.SetReal(keys::kTimeStampKey, | 117 args.SetDouble(keys::kTimeStampKey, |
118 base::Time::kMillisecondsPerSecond * time_stamp.ToDoubleT()); | 118 base::Time::kMillisecondsPerSecond * time_stamp.ToDoubleT()); |
119 | 119 |
120 EXPECT_CALL(webrequest_events_funnel, | 120 EXPECT_CALL(webrequest_events_funnel, |
121 SendEvent(StrEq(keys::kOnErrorOccurred), ValuesEqual(&args))) | 121 SendEvent(StrEq(keys::kOnErrorOccurred), ValuesEqual(&args))) |
122 .WillOnce(Return(S_OK)); | 122 .WillOnce(Return(S_OK)); |
123 EXPECT_HRESULT_SUCCEEDED(webrequest_events_funnel.OnErrorOccurred( | 123 EXPECT_HRESULT_SUCCEEDED(webrequest_events_funnel.OnErrorOccurred( |
124 request_id, url.c_str(), error.c_str(), time_stamp)); | 124 request_id, url.c_str(), error.c_str(), time_stamp)); |
125 } | 125 } |
126 | 126 |
127 TEST(WebRequestEventsFunnelTest, OnHeadersReceived) { | 127 TEST(WebRequestEventsFunnelTest, OnHeadersReceived) { |
128 TestWebRequestEventsFunnel webrequest_events_funnel; | 128 TestWebRequestEventsFunnel webrequest_events_funnel; |
129 | 129 |
130 int request_id = 256; | 130 int request_id = 256; |
131 std::wstring url(L"http://news.google.com/"); | 131 std::wstring url(L"http://news.google.com/"); |
132 DWORD status_code = 200; | 132 DWORD status_code = 200; |
133 base::Time time_stamp = base::Time::FromDoubleT(2048.0); | 133 base::Time time_stamp = base::Time::FromDoubleT(2048.0); |
134 | 134 |
135 DictionaryValue args; | 135 DictionaryValue args; |
136 args.SetInteger(keys::kRequestIdKey, request_id); | 136 args.SetInteger(keys::kRequestIdKey, request_id); |
137 args.SetString(keys::kUrlKey, url); | 137 args.SetString(keys::kUrlKey, url); |
138 args.SetInteger(keys::kStatusCodeKey, status_code); | 138 args.SetInteger(keys::kStatusCodeKey, status_code); |
139 args.SetReal(keys::kTimeStampKey, | 139 args.SetDouble(keys::kTimeStampKey, |
140 base::Time::kMillisecondsPerSecond * time_stamp.ToDoubleT()); | 140 base::Time::kMillisecondsPerSecond * time_stamp.ToDoubleT()); |
141 | 141 |
142 EXPECT_CALL(webrequest_events_funnel, | 142 EXPECT_CALL(webrequest_events_funnel, |
143 SendEvent(StrEq(keys::kOnHeadersReceived), ValuesEqual(&args))) | 143 SendEvent(StrEq(keys::kOnHeadersReceived), ValuesEqual(&args))) |
144 .WillOnce(Return(S_OK)); | 144 .WillOnce(Return(S_OK)); |
145 EXPECT_HRESULT_SUCCEEDED(webrequest_events_funnel.OnHeadersReceived( | 145 EXPECT_HRESULT_SUCCEEDED(webrequest_events_funnel.OnHeadersReceived( |
146 request_id, url.c_str(), status_code, time_stamp)); | 146 request_id, url.c_str(), status_code, time_stamp)); |
147 } | 147 } |
148 | 148 |
149 TEST(WebRequestEventsFunnelTest, OnRequestSent) { | 149 TEST(WebRequestEventsFunnelTest, OnRequestSent) { |
150 TestWebRequestEventsFunnel webrequest_events_funnel; | 150 TestWebRequestEventsFunnel webrequest_events_funnel; |
151 | 151 |
152 int request_id = 256; | 152 int request_id = 256; |
153 std::wstring url(L"http://finance.google.com/"); | 153 std::wstring url(L"http://finance.google.com/"); |
154 std::string ip("127.0.0.1"); | 154 std::string ip("127.0.0.1"); |
155 base::Time time_stamp = base::Time::FromDoubleT(2048.0); | 155 base::Time time_stamp = base::Time::FromDoubleT(2048.0); |
156 | 156 |
157 DictionaryValue args; | 157 DictionaryValue args; |
158 args.SetInteger(keys::kRequestIdKey, request_id); | 158 args.SetInteger(keys::kRequestIdKey, request_id); |
159 args.SetString(keys::kUrlKey, url); | 159 args.SetString(keys::kUrlKey, url); |
160 args.SetString(keys::kIpKey, ip); | 160 args.SetString(keys::kIpKey, ip); |
161 args.SetReal(keys::kTimeStampKey, | 161 args.SetDouble(keys::kTimeStampKey, |
162 base::Time::kMillisecondsPerSecond * time_stamp.ToDoubleT()); | 162 base::Time::kMillisecondsPerSecond * time_stamp.ToDoubleT()); |
163 | 163 |
164 EXPECT_CALL(webrequest_events_funnel, | 164 EXPECT_CALL(webrequest_events_funnel, |
165 SendEvent(StrEq(keys::kOnRequestSent), ValuesEqual(&args))) | 165 SendEvent(StrEq(keys::kOnRequestSent), ValuesEqual(&args))) |
166 .WillOnce(Return(S_OK)); | 166 .WillOnce(Return(S_OK)); |
167 EXPECT_HRESULT_SUCCEEDED(webrequest_events_funnel.OnRequestSent( | 167 EXPECT_HRESULT_SUCCEEDED(webrequest_events_funnel.OnRequestSent( |
168 request_id, url.c_str(), ip.c_str(), time_stamp)); | 168 request_id, url.c_str(), ip.c_str(), time_stamp)); |
169 } | 169 } |
170 | 170 |
171 } // namespace | 171 } // namespace |
OLD | NEW |