| 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 WebNavigationEventsFunnel. | 5 // Unit tests for WebNavigationEventsFunnel. |
| 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 27 matching lines...) Expand all Loading... |
| 38 std::string url("http://www.google.com/"); | 38 std::string url("http://www.google.com/"); |
| 39 int frame_id = 512; | 39 int frame_id = 512; |
| 40 int request_id = 1024; | 40 int request_id = 1024; |
| 41 base::Time time_stamp = base::Time::FromDoubleT(2048.0); | 41 base::Time time_stamp = base::Time::FromDoubleT(2048.0); |
| 42 | 42 |
| 43 DictionaryValue args; | 43 DictionaryValue args; |
| 44 args.SetInteger(keys::kTabIdKey, tab_handle); | 44 args.SetInteger(keys::kTabIdKey, tab_handle); |
| 45 args.SetString(keys::kUrlKey, url); | 45 args.SetString(keys::kUrlKey, url); |
| 46 args.SetInteger(keys::kFrameIdKey, frame_id); | 46 args.SetInteger(keys::kFrameIdKey, frame_id); |
| 47 args.SetInteger(keys::kRequestIdKey, request_id); | 47 args.SetInteger(keys::kRequestIdKey, request_id); |
| 48 args.SetReal(keys::kTimeStampKey, | 48 args.SetDouble(keys::kTimeStampKey, |
| 49 base::Time::kMillisecondsPerSecond * time_stamp.ToDoubleT()); | 49 base::Time::kMillisecondsPerSecond * time_stamp.ToDoubleT()); |
| 50 | 50 |
| 51 EXPECT_CALL(webnavigation_events_funnel, | 51 EXPECT_CALL(webnavigation_events_funnel, |
| 52 SendEvent(StrEq(keys::kOnBeforeNavigate), ValuesEqual(&args))) | 52 SendEvent(StrEq(keys::kOnBeforeNavigate), ValuesEqual(&args))) |
| 53 .WillOnce(Return(S_OK)); | 53 .WillOnce(Return(S_OK)); |
| 54 EXPECT_HRESULT_SUCCEEDED(webnavigation_events_funnel.OnBeforeNavigate( | 54 EXPECT_HRESULT_SUCCEEDED(webnavigation_events_funnel.OnBeforeNavigate( |
| 55 static_cast<CeeeWindowHandle>(tab_handle), CComBSTR(url.c_str()), | 55 static_cast<CeeeWindowHandle>(tab_handle), CComBSTR(url.c_str()), |
| 56 frame_id, request_id, time_stamp)); | 56 frame_id, request_id, time_stamp)); |
| 57 } | 57 } |
| 58 | 58 |
| 59 TEST(WebNavigationEventsFunnelTest, OnBeforeRetarget) { | 59 TEST(WebNavigationEventsFunnelTest, OnBeforeRetarget) { |
| 60 TestWebNavigationEventsFunnel webnavigation_events_funnel; | 60 TestWebNavigationEventsFunnel webnavigation_events_funnel; |
| 61 | 61 |
| 62 int source_tab_handle = 256; | 62 int source_tab_handle = 256; |
| 63 std::string source_url("http://docs.google.com/"); | 63 std::string source_url("http://docs.google.com/"); |
| 64 std::string target_url("http://calendar.google.com/"); | 64 std::string target_url("http://calendar.google.com/"); |
| 65 base::Time time_stamp = base::Time::FromDoubleT(2048.0); | 65 base::Time time_stamp = base::Time::FromDoubleT(2048.0); |
| 66 | 66 |
| 67 DictionaryValue args; | 67 DictionaryValue args; |
| 68 args.SetInteger(keys::kSourceTabIdKey, source_tab_handle); | 68 args.SetInteger(keys::kSourceTabIdKey, source_tab_handle); |
| 69 args.SetString(keys::kSourceUrlKey, source_url); | 69 args.SetString(keys::kSourceUrlKey, source_url); |
| 70 args.SetString(keys::kTargetUrlKey, target_url); | 70 args.SetString(keys::kTargetUrlKey, target_url); |
| 71 args.SetReal(keys::kTimeStampKey, | 71 args.SetDouble(keys::kTimeStampKey, |
| 72 base::Time::kMillisecondsPerSecond * time_stamp.ToDoubleT()); | 72 base::Time::kMillisecondsPerSecond * time_stamp.ToDoubleT()); |
| 73 | 73 |
| 74 EXPECT_CALL(webnavigation_events_funnel, | 74 EXPECT_CALL(webnavigation_events_funnel, |
| 75 SendEvent(StrEq(keys::kOnBeforeRetarget), ValuesEqual(&args))) | 75 SendEvent(StrEq(keys::kOnBeforeRetarget), ValuesEqual(&args))) |
| 76 .WillOnce(Return(S_OK)); | 76 .WillOnce(Return(S_OK)); |
| 77 EXPECT_HRESULT_SUCCEEDED(webnavigation_events_funnel.OnBeforeRetarget( | 77 EXPECT_HRESULT_SUCCEEDED(webnavigation_events_funnel.OnBeforeRetarget( |
| 78 static_cast<CeeeWindowHandle>(source_tab_handle), | 78 static_cast<CeeeWindowHandle>(source_tab_handle), |
| 79 CComBSTR(source_url.c_str()), CComBSTR(target_url.c_str()), time_stamp)); | 79 CComBSTR(source_url.c_str()), CComBSTR(target_url.c_str()), time_stamp)); |
| 80 } | 80 } |
| 81 | 81 |
| 82 TEST(WebNavigationEventsFunnelTest, OnCommitted) { | 82 TEST(WebNavigationEventsFunnelTest, OnCommitted) { |
| 83 TestWebNavigationEventsFunnel webnavigation_events_funnel; | 83 TestWebNavigationEventsFunnel webnavigation_events_funnel; |
| 84 | 84 |
| 85 int tab_handle = 256; | 85 int tab_handle = 256; |
| 86 std::string url("http://mail.google.com/"); | 86 std::string url("http://mail.google.com/"); |
| 87 int frame_id = 512; | 87 int frame_id = 512; |
| 88 std::string transition_type("link"); | 88 std::string transition_type("link"); |
| 89 std::string transition_qualifiers("client_redirect"); | 89 std::string transition_qualifiers("client_redirect"); |
| 90 base::Time time_stamp = base::Time::FromDoubleT(2048.0); | 90 base::Time time_stamp = base::Time::FromDoubleT(2048.0); |
| 91 | 91 |
| 92 DictionaryValue args; | 92 DictionaryValue args; |
| 93 args.SetInteger(keys::kTabIdKey, tab_handle); | 93 args.SetInteger(keys::kTabIdKey, tab_handle); |
| 94 args.SetString(keys::kUrlKey, url); | 94 args.SetString(keys::kUrlKey, url); |
| 95 args.SetInteger(keys::kFrameIdKey, frame_id); | 95 args.SetInteger(keys::kFrameIdKey, frame_id); |
| 96 args.SetString(keys::kTransitionTypeKey, transition_type); | 96 args.SetString(keys::kTransitionTypeKey, transition_type); |
| 97 args.SetString(keys::kTransitionQualifiersKey, transition_qualifiers); | 97 args.SetString(keys::kTransitionQualifiersKey, transition_qualifiers); |
| 98 args.SetReal(keys::kTimeStampKey, | 98 args.SetDouble(keys::kTimeStampKey, |
| 99 base::Time::kMillisecondsPerSecond * time_stamp.ToDoubleT()); | 99 base::Time::kMillisecondsPerSecond * time_stamp.ToDoubleT()); |
| 100 | 100 |
| 101 EXPECT_CALL(webnavigation_events_funnel, | 101 EXPECT_CALL(webnavigation_events_funnel, |
| 102 SendEvent(StrEq(keys::kOnCommitted), ValuesEqual(&args))) | 102 SendEvent(StrEq(keys::kOnCommitted), ValuesEqual(&args))) |
| 103 .WillOnce(Return(S_OK)); | 103 .WillOnce(Return(S_OK)); |
| 104 EXPECT_HRESULT_SUCCEEDED(webnavigation_events_funnel.OnCommitted( | 104 EXPECT_HRESULT_SUCCEEDED(webnavigation_events_funnel.OnCommitted( |
| 105 static_cast<CeeeWindowHandle>(tab_handle), CComBSTR(url.c_str()), | 105 static_cast<CeeeWindowHandle>(tab_handle), CComBSTR(url.c_str()), |
| 106 frame_id, transition_type.c_str(), transition_qualifiers.c_str(), | 106 frame_id, transition_type.c_str(), transition_qualifiers.c_str(), |
| 107 time_stamp)); | 107 time_stamp)); |
| 108 } | 108 } |
| 109 | 109 |
| 110 TEST(WebNavigationEventsFunnelTest, OnCompleted) { | 110 TEST(WebNavigationEventsFunnelTest, OnCompleted) { |
| 111 TestWebNavigationEventsFunnel webnavigation_events_funnel; | 111 TestWebNavigationEventsFunnel webnavigation_events_funnel; |
| 112 | 112 |
| 113 int tab_handle = 256; | 113 int tab_handle = 256; |
| 114 std::string url("http://groups.google.com/"); | 114 std::string url("http://groups.google.com/"); |
| 115 int frame_id = 512; | 115 int frame_id = 512; |
| 116 base::Time time_stamp = base::Time::FromDoubleT(2048.0); | 116 base::Time time_stamp = base::Time::FromDoubleT(2048.0); |
| 117 | 117 |
| 118 DictionaryValue args; | 118 DictionaryValue args; |
| 119 args.SetInteger(keys::kTabIdKey, tab_handle); | 119 args.SetInteger(keys::kTabIdKey, tab_handle); |
| 120 args.SetString(keys::kUrlKey, url); | 120 args.SetString(keys::kUrlKey, url); |
| 121 args.SetInteger(keys::kFrameIdKey, frame_id); | 121 args.SetInteger(keys::kFrameIdKey, frame_id); |
| 122 args.SetReal(keys::kTimeStampKey, | 122 args.SetDouble(keys::kTimeStampKey, |
| 123 base::Time::kMillisecondsPerSecond * time_stamp.ToDoubleT()); | 123 base::Time::kMillisecondsPerSecond * time_stamp.ToDoubleT()); |
| 124 | 124 |
| 125 EXPECT_CALL(webnavigation_events_funnel, | 125 EXPECT_CALL(webnavigation_events_funnel, |
| 126 SendEvent(StrEq(keys::kOnCompleted), ValuesEqual(&args))) | 126 SendEvent(StrEq(keys::kOnCompleted), ValuesEqual(&args))) |
| 127 .WillOnce(Return(S_OK)); | 127 .WillOnce(Return(S_OK)); |
| 128 EXPECT_HRESULT_SUCCEEDED(webnavigation_events_funnel.OnCompleted( | 128 EXPECT_HRESULT_SUCCEEDED(webnavigation_events_funnel.OnCompleted( |
| 129 static_cast<CeeeWindowHandle>(tab_handle), CComBSTR(url.c_str()), | 129 static_cast<CeeeWindowHandle>(tab_handle), CComBSTR(url.c_str()), |
| 130 frame_id, time_stamp)); | 130 frame_id, time_stamp)); |
| 131 } | 131 } |
| 132 | 132 |
| 133 TEST(WebNavigationEventsFunnelTest, OnDOMContentLoaded) { | 133 TEST(WebNavigationEventsFunnelTest, OnDOMContentLoaded) { |
| 134 TestWebNavigationEventsFunnel webnavigation_events_funnel; | 134 TestWebNavigationEventsFunnel webnavigation_events_funnel; |
| 135 | 135 |
| 136 int tab_handle = 256; | 136 int tab_handle = 256; |
| 137 std::string url("http://mail.google.com/"); | 137 std::string url("http://mail.google.com/"); |
| 138 int frame_id = 512; | 138 int frame_id = 512; |
| 139 base::Time time_stamp = base::Time::FromDoubleT(2048.0); | 139 base::Time time_stamp = base::Time::FromDoubleT(2048.0); |
| 140 | 140 |
| 141 DictionaryValue args; | 141 DictionaryValue args; |
| 142 args.SetInteger(keys::kTabIdKey, tab_handle); | 142 args.SetInteger(keys::kTabIdKey, tab_handle); |
| 143 args.SetString(keys::kUrlKey, url); | 143 args.SetString(keys::kUrlKey, url); |
| 144 args.SetInteger(keys::kFrameIdKey, frame_id); | 144 args.SetInteger(keys::kFrameIdKey, frame_id); |
| 145 args.SetReal(keys::kTimeStampKey, | 145 args.SetDouble(keys::kTimeStampKey, |
| 146 base::Time::kMillisecondsPerSecond * time_stamp.ToDoubleT()); | 146 base::Time::kMillisecondsPerSecond * time_stamp.ToDoubleT()); |
| 147 | 147 |
| 148 EXPECT_CALL(webnavigation_events_funnel, | 148 EXPECT_CALL(webnavigation_events_funnel, |
| 149 SendEvent(StrEq(keys::kOnDOMContentLoaded), ValuesEqual(&args))) | 149 SendEvent(StrEq(keys::kOnDOMContentLoaded), ValuesEqual(&args))) |
| 150 .WillOnce(Return(S_OK)); | 150 .WillOnce(Return(S_OK)); |
| 151 EXPECT_HRESULT_SUCCEEDED(webnavigation_events_funnel.OnDOMContentLoaded( | 151 EXPECT_HRESULT_SUCCEEDED(webnavigation_events_funnel.OnDOMContentLoaded( |
| 152 static_cast<CeeeWindowHandle>(tab_handle), CComBSTR(url.c_str()), | 152 static_cast<CeeeWindowHandle>(tab_handle), CComBSTR(url.c_str()), |
| 153 frame_id, time_stamp)); | 153 frame_id, time_stamp)); |
| 154 } | 154 } |
| 155 | 155 |
| 156 TEST(WebNavigationEventsFunnelTest, OnErrorOccurred) { | 156 TEST(WebNavigationEventsFunnelTest, OnErrorOccurred) { |
| 157 TestWebNavigationEventsFunnel webnavigation_events_funnel; | 157 TestWebNavigationEventsFunnel webnavigation_events_funnel; |
| 158 | 158 |
| 159 int tab_handle = 256; | 159 int tab_handle = 256; |
| 160 std::string url("http://mail.google.com/"); | 160 std::string url("http://mail.google.com/"); |
| 161 int frame_id = 512; | 161 int frame_id = 512; |
| 162 std::string error("not a valid URL"); | 162 std::string error("not a valid URL"); |
| 163 base::Time time_stamp = base::Time::FromDoubleT(2048.0); | 163 base::Time time_stamp = base::Time::FromDoubleT(2048.0); |
| 164 | 164 |
| 165 DictionaryValue args; | 165 DictionaryValue args; |
| 166 args.SetInteger(keys::kTabIdKey, tab_handle); | 166 args.SetInteger(keys::kTabIdKey, tab_handle); |
| 167 args.SetString(keys::kUrlKey, url); | 167 args.SetString(keys::kUrlKey, url); |
| 168 args.SetInteger(keys::kFrameIdKey, frame_id); | 168 args.SetInteger(keys::kFrameIdKey, frame_id); |
| 169 args.SetString(keys::kErrorKey, error); | 169 args.SetString(keys::kErrorKey, error); |
| 170 args.SetReal(keys::kTimeStampKey, | 170 args.SetDouble(keys::kTimeStampKey, |
| 171 base::Time::kMillisecondsPerSecond * time_stamp.ToDoubleT()); | 171 base::Time::kMillisecondsPerSecond * time_stamp.ToDoubleT()); |
| 172 | 172 |
| 173 EXPECT_CALL(webnavigation_events_funnel, | 173 EXPECT_CALL(webnavigation_events_funnel, |
| 174 SendEvent(StrEq(keys::kOnErrorOccurred), ValuesEqual(&args))) | 174 SendEvent(StrEq(keys::kOnErrorOccurred), ValuesEqual(&args))) |
| 175 .WillOnce(Return(S_OK)); | 175 .WillOnce(Return(S_OK)); |
| 176 EXPECT_HRESULT_SUCCEEDED(webnavigation_events_funnel.OnErrorOccurred( | 176 EXPECT_HRESULT_SUCCEEDED(webnavigation_events_funnel.OnErrorOccurred( |
| 177 static_cast<CeeeWindowHandle>(tab_handle), CComBSTR(url.c_str()), | 177 static_cast<CeeeWindowHandle>(tab_handle), CComBSTR(url.c_str()), |
| 178 frame_id, CComBSTR(error.c_str()), time_stamp)); | 178 frame_id, CComBSTR(error.c_str()), time_stamp)); |
| 179 } | 179 } |
| 180 | 180 |
| 181 } // namespace | 181 } // namespace |
| OLD | NEW |