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

Side by Side Diff: chrome_frame/test/chrome_frame_unittests.cc

Issue 385111: Merge 31792 - The ChromeFrameAutomationClient class needs to be refcounted as... (Closed) Base URL: svn://svn.chromium.org/chrome/branches/245/src/
Patch Set: Created 11 years, 1 month 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
« no previous file with comments | « chrome_frame/test/chrome_frame_automation_mock.h ('k') | chrome_frame/urlmon_url_request.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 #include <windows.h> 4 #include <windows.h>
5 #include <stdarg.h> 5 #include <stdarg.h>
6 6
7 // IShellWindows includes. Unfortunately we can't keep these in 7 // IShellWindows includes. Unfortunately we can't keep these in
8 // alphabetic order since exdisp will bark if some interfaces aren't fully 8 // alphabetic order since exdisp will bark if some interfaces aren't fully
9 // defined. 9 // defined.
10 #include <mshtml.h> 10 #include <mshtml.h>
(...skipping 883 matching lines...) Expand 10 before | Expand all | Expand 10 after
894 #define QUIT_LOOP_SOON(loop, seconds) testing::InvokeWithoutArgs(\ 894 #define QUIT_LOOP_SOON(loop, seconds) testing::InvokeWithoutArgs(\
895 CreateFunctor(&loop, &TimedMsgLoop::QuitAfter, seconds)) 895 CreateFunctor(&loop, &TimedMsgLoop::QuitAfter, seconds))
896 896
897 // We mock ChromeFrameDelegate only. The rest is with real AutomationProxy 897 // We mock ChromeFrameDelegate only. The rest is with real AutomationProxy
898 TEST(CFACWithChrome, CreateTooFast) { 898 TEST(CFACWithChrome, CreateTooFast) {
899 MockCFDelegate cfd; 899 MockCFDelegate cfd;
900 TimedMsgLoop loop; 900 TimedMsgLoop loop;
901 int timeout = 0; // Chrome cannot send Hello message so fast. 901 int timeout = 0; // Chrome cannot send Hello message so fast.
902 const std::wstring profile = L"Adam.N.Epilinter"; 902 const std::wstring profile = L"Adam.N.Epilinter";
903 903
904 scoped_ptr<ChromeFrameAutomationClient> client; 904 scoped_refptr<ChromeFrameAutomationClient> client;
905 client.reset(new ChromeFrameAutomationClient()); 905 client = new ChromeFrameAutomationClient();
906 906
907 EXPECT_CALL(cfd, OnAutomationServerLaunchFailed(AUTOMATION_TIMEOUT, 907 EXPECT_CALL(cfd, OnAutomationServerLaunchFailed(AUTOMATION_TIMEOUT,
908 testing::_)) 908 testing::_))
909 .Times(1) 909 .Times(1)
910 .WillOnce(QUIT_LOOP(loop)); 910 .WillOnce(QUIT_LOOP(loop));
911 911
912 EXPECT_TRUE(client->Initialize(&cfd, timeout, false, profile, L"", false)); 912 EXPECT_TRUE(client->Initialize(&cfd, timeout, false, profile, L"", false));
913 loop.RunFor(10); 913 loop.RunFor(10);
914 client->Uninitialize(); 914 client->Uninitialize();
915 } 915 }
916 916
917 // This test may fail if Chrome take more that 10 seconds (timeout var) to 917 // This test may fail if Chrome take more that 10 seconds (timeout var) to
918 // launch. In this case GMock shall print something like "unexpected call to 918 // launch. In this case GMock shall print something like "unexpected call to
919 // OnAutomationServerLaunchFailed". I'm yet to find out how to specify 919 // OnAutomationServerLaunchFailed". I'm yet to find out how to specify
920 // that this is an unexpected call, and still to execute and action. 920 // that this is an unexpected call, and still to execute and action.
921 TEST(CFACWithChrome, CreateNotSoFast) { 921 TEST(CFACWithChrome, CreateNotSoFast) {
922 MockCFDelegate cfd; 922 MockCFDelegate cfd;
923 TimedMsgLoop loop; 923 TimedMsgLoop loop;
924 const std::wstring profile = L"Adam.N.Epilinter"; 924 const std::wstring profile = L"Adam.N.Epilinter";
925 int timeout = 10000; 925 int timeout = 10000;
926 926
927 scoped_ptr<ChromeFrameAutomationClient> client; 927 scoped_refptr<ChromeFrameAutomationClient> client;
928 client.reset(new ChromeFrameAutomationClient); 928 client = new ChromeFrameAutomationClient;
929 929
930 EXPECT_CALL(cfd, OnAutomationServerReady()) 930 EXPECT_CALL(cfd, OnAutomationServerReady())
931 .Times(1) 931 .Times(1)
932 .WillOnce(QUIT_LOOP(loop)); 932 .WillOnce(QUIT_LOOP(loop));
933 933
934 EXPECT_CALL(cfd, OnAutomationServerLaunchFailed(testing::_, testing::_)) 934 EXPECT_CALL(cfd, OnAutomationServerLaunchFailed(testing::_, testing::_))
935 .Times(0); 935 .Times(0);
936 936
937 EXPECT_TRUE(client->Initialize(&cfd, timeout, false, profile, L"", false)); 937 EXPECT_TRUE(client->Initialize(&cfd, timeout, false, profile, L"", false));
938 938
939 loop.RunFor(11); 939 loop.RunFor(11);
940 client->Uninitialize(); 940 client->Uninitialize();
941 client.reset(NULL); 941 client = NULL;
942 } 942 }
943 943
944 MATCHER_P(MsgType, msg_type, "IPC::Message::type()") { 944 MATCHER_P(MsgType, msg_type, "IPC::Message::type()") {
945 const IPC::Message& m = arg; 945 const IPC::Message& m = arg;
946 return (m.type() == msg_type); 946 return (m.type() == msg_type);
947 } 947 }
948 948
949 MATCHER_P(EqNavigationInfoUrl, url, "IPC::NavigationInfo matcher") { 949 MATCHER_P(EqNavigationInfoUrl, url, "IPC::NavigationInfo matcher") {
950 if (url.is_valid() && url != arg.url) 950 if (url.is_valid() && url != arg.url)
951 return false; 951 return false;
952 // TODO(stevet): other members 952 // TODO(stevet): other members
953 return true; 953 return true;
954 } 954 }
955 955
956 TEST(CFACWithChrome, NavigateOk) { 956 TEST(CFACWithChrome, NavigateOk) {
957 MockCFDelegate cfd; 957 MockCFDelegate cfd;
958 TimedMsgLoop loop; 958 TimedMsgLoop loop;
959 const std::wstring profile = L"Adam.N.Epilinter"; 959 const std::wstring profile = L"Adam.N.Epilinter";
960 const std::string url = "about:version"; 960 const std::string url = "about:version";
961 int timeout = 10000; 961 int timeout = 10000;
962 962
963 scoped_ptr<ChromeFrameAutomationClient> client; 963 scoped_refptr<ChromeFrameAutomationClient> client;
964 client.reset(new ChromeFrameAutomationClient); 964 client = new ChromeFrameAutomationClient;
965 965
966 EXPECT_CALL(cfd, OnAutomationServerReady()) 966 EXPECT_CALL(cfd, OnAutomationServerReady())
967 .WillOnce(testing::IgnoreResult(testing::InvokeWithoutArgs(CreateFunctor( 967 .WillOnce(testing::IgnoreResult(testing::InvokeWithoutArgs(CreateFunctor(
968 client.get(), &ChromeFrameAutomationClient::InitiateNavigation, 968 client.get(), &ChromeFrameAutomationClient::InitiateNavigation,
969 url, std::string(), false)))); 969 url, std::string(), false))));
970 970
971 // cfd.SetOnNavigationStateChanged(); 971 // cfd.SetOnNavigationStateChanged();
972 EXPECT_CALL(cfd, 972 EXPECT_CALL(cfd,
973 OnNavigationStateChanged(testing::_, testing::_)) 973 OnNavigationStateChanged(testing::_, testing::_))
974 .Times(testing::AnyNumber()); 974 .Times(testing::AnyNumber());
975 975
976 { 976 {
977 testing::InSequence s; 977 testing::InSequence s;
978 978
979 EXPECT_CALL(cfd, OnDidNavigate(testing::_, EqNavigationInfoUrl(GURL()))) 979 EXPECT_CALL(cfd, OnDidNavigate(testing::_, EqNavigationInfoUrl(GURL())))
980 .Times(1); 980 .Times(1);
981 981
982 EXPECT_CALL(cfd, OnUpdateTargetUrl(testing::_, testing::_)).Times(1); 982 EXPECT_CALL(cfd, OnUpdateTargetUrl(testing::_, testing::_)).Times(1);
983 983
984 EXPECT_CALL(cfd, OnLoad(testing::_, testing::_)) 984 EXPECT_CALL(cfd, OnLoad(testing::_, testing::_))
985 .Times(1) 985 .Times(1)
986 .WillOnce(QUIT_LOOP(loop)); 986 .WillOnce(QUIT_LOOP(loop));
987 } 987 }
988 988
989 EXPECT_TRUE(client->Initialize(&cfd, timeout, false, profile, L"", false)); 989 EXPECT_TRUE(client->Initialize(&cfd, timeout, false, profile, L"", false));
990 loop.RunFor(10); 990 loop.RunFor(10);
991 client->Uninitialize(); 991 client->Uninitialize();
992 client.reset(NULL); 992 client = NULL;
993 } 993 }
994 994
995 // Bug: http://b/issue?id=2033644 995 // Bug: http://b/issue?id=2033644
996 TEST(CFACWithChrome, DISABLED_NavigateFailed) { 996 TEST(CFACWithChrome, DISABLED_NavigateFailed) {
997 MockCFDelegate cfd; 997 MockCFDelegate cfd;
998 TimedMsgLoop loop; 998 TimedMsgLoop loop;
999 const std::wstring profile = L"Adam.N.Epilinter"; 999 const std::wstring profile = L"Adam.N.Epilinter";
1000 const std::string url = "http://127.0.0.3:65412/"; 1000 const std::string url = "http://127.0.0.3:65412/";
1001 int timeout = 10000; 1001 int timeout = 10000;
1002 1002
1003 scoped_ptr<ChromeFrameAutomationClient> client; 1003 scoped_refptr<ChromeFrameAutomationClient> client;
1004 client.reset(new ChromeFrameAutomationClient); 1004 client = new ChromeFrameAutomationClient;
1005 1005
1006 EXPECT_CALL(cfd, OnAutomationServerReady()) 1006 EXPECT_CALL(cfd, OnAutomationServerReady())
1007 .WillOnce(testing::IgnoreResult(testing::InvokeWithoutArgs(CreateFunctor( 1007 .WillOnce(testing::IgnoreResult(testing::InvokeWithoutArgs(CreateFunctor(
1008 client.get(), &ChromeFrameAutomationClient::InitiateNavigation, 1008 client.get(), &ChromeFrameAutomationClient::InitiateNavigation,
1009 url, std::string(), false)))); 1009 url, std::string(), false))));
1010 1010
1011 EXPECT_CALL(cfd, 1011 EXPECT_CALL(cfd,
1012 OnNavigationStateChanged(testing::_, testing::_)) 1012 OnNavigationStateChanged(testing::_, testing::_))
1013 .Times(testing::AnyNumber()); 1013 .Times(testing::AnyNumber());
1014 1014
1015 EXPECT_CALL(cfd, OnNavigationFailed(testing::_, testing::_, testing::_)) 1015 EXPECT_CALL(cfd, OnNavigationFailed(testing::_, testing::_, testing::_))
1016 .Times(1); 1016 .Times(1);
1017 1017
1018 EXPECT_CALL(cfd, OnUpdateTargetUrl(testing::_, testing::_)) 1018 EXPECT_CALL(cfd, OnUpdateTargetUrl(testing::_, testing::_))
1019 .Times(testing::AnyNumber()); 1019 .Times(testing::AnyNumber());
1020 1020
1021 EXPECT_CALL(cfd, OnLoad(testing::_, testing::_)) 1021 EXPECT_CALL(cfd, OnLoad(testing::_, testing::_))
1022 .Times(0); 1022 .Times(0);
1023 1023
1024 EXPECT_TRUE(client->Initialize(&cfd, timeout, false, profile, L"", false)); 1024 EXPECT_TRUE(client->Initialize(&cfd, timeout, false, profile, L"", false));
1025 1025
1026 loop.RunFor(10); 1026 loop.RunFor(10);
1027 client->Uninitialize(); 1027 client->Uninitialize();
1028 client.reset(NULL); 1028 client = NULL;
1029 } 1029 }
1030 1030
1031 MATCHER_P(EqURLRequest, x, "IPC::AutomationURLRequest matcher") { 1031 MATCHER_P(EqURLRequest, x, "IPC::AutomationURLRequest matcher") {
1032 if (arg.url != x.url) 1032 if (arg.url != x.url)
1033 return false; 1033 return false;
1034 if (arg.method != x.method) 1034 if (arg.method != x.method)
1035 return false; 1035 return false;
1036 if (arg.referrer != x.referrer) 1036 if (arg.referrer != x.referrer)
1037 return false; 1037 return false;
1038 if (arg.extra_request_headers != x.extra_request_headers) 1038 if (arg.extra_request_headers != x.extra_request_headers)
(...skipping 10 matching lines...) Expand all
1049 return true; 1049 return true;
1050 } 1050 }
1051 1051
1052 TEST(CFACWithChrome, UseHostNetworkStack) { 1052 TEST(CFACWithChrome, UseHostNetworkStack) {
1053 MockCFDelegate cfd; 1053 MockCFDelegate cfd;
1054 TimedMsgLoop loop; 1054 TimedMsgLoop loop;
1055 const std::wstring profile = L"Adam.N.Epilinter"; 1055 const std::wstring profile = L"Adam.N.Epilinter";
1056 const std::string url = "http://bongo.com"; 1056 const std::string url = "http://bongo.com";
1057 int timeout = 10000; 1057 int timeout = 10000;
1058 1058
1059 scoped_ptr<ChromeFrameAutomationClient> client; 1059 scoped_refptr<ChromeFrameAutomationClient> client;
1060 client.reset(new ChromeFrameAutomationClient); 1060 client = new ChromeFrameAutomationClient;
1061 client->set_use_chrome_network(false); 1061 client->set_use_chrome_network(false);
1062 cfd.SetAutomationSender(client.get()); 1062 cfd.SetAutomationSender(client.get());
1063 1063
1064 EXPECT_CALL(cfd, OnAutomationServerReady()) 1064 EXPECT_CALL(cfd, OnAutomationServerReady())
1065 .WillOnce(testing::IgnoreResult(testing::InvokeWithoutArgs(CreateFunctor( 1065 .WillOnce(testing::IgnoreResult(testing::InvokeWithoutArgs(CreateFunctor(
1066 client.get(), &ChromeFrameAutomationClient::InitiateNavigation, 1066 client.get(), &ChromeFrameAutomationClient::InitiateNavigation,
1067 url, std::string(), false)))); 1067 url, std::string(), false))));
1068 1068
1069 EXPECT_CALL(cfd, OnNavigationStateChanged(testing::_, testing::_)) 1069 EXPECT_CALL(cfd, OnNavigationStateChanged(testing::_, testing::_))
1070 .Times(testing::AnyNumber()); 1070 .Times(testing::AnyNumber());
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
1124 1124
1125 EXPECT_CALL(cfd, OnRequestRead(tab_id, request_id, testing::_)) 1125 EXPECT_CALL(cfd, OnRequestRead(tab_id, request_id, testing::_))
1126 .Times(testing::AtMost(1)); 1126 .Times(testing::AtMost(1));
1127 1127
1128 bool incognito = true; 1128 bool incognito = true;
1129 EXPECT_TRUE(client->Initialize(&cfd, timeout, false, profile, L"", 1129 EXPECT_TRUE(client->Initialize(&cfd, timeout, false, profile, L"",
1130 incognito)); 1130 incognito));
1131 1131
1132 loop.RunFor(10); 1132 loop.RunFor(10);
1133 client->Uninitialize(); 1133 client->Uninitialize();
1134 client.reset(NULL); 1134 client = NULL;
1135 } 1135 }
1136 1136
1137 1137
1138 // [CFAC] -- uses a ProxyFactory for creation of ChromeFrameAutomationProxy 1138 // [CFAC] -- uses a ProxyFactory for creation of ChromeFrameAutomationProxy
1139 // -- uses ChromeFrameAutomationProxy 1139 // -- uses ChromeFrameAutomationProxy
1140 // -- uses TabProxy obtained from ChromeFrameAutomationProxy 1140 // -- uses TabProxy obtained from ChromeFrameAutomationProxy
1141 // -- uses ChromeFrameDelegate as outgoing interface 1141 // -- uses ChromeFrameDelegate as outgoing interface
1142 // 1142 //
1143 // We mock ProxyFactory to return mock object (MockAutomationProxy) implementing 1143 // We mock ProxyFactory to return mock object (MockAutomationProxy) implementing
1144 // ChromeFrameAutomationProxy interface. 1144 // ChromeFrameAutomationProxy interface.
1145 // Since CFAC uses TabProxy for few calls and TabProxy is not easy mockable, 1145 // Since CFAC uses TabProxy for few calls and TabProxy is not easy mockable,
1146 // we create 'real' TabProxy but with fake AutomationSender (the one responsible 1146 // we create 'real' TabProxy but with fake AutomationSender (the one responsible
1147 // for sending messages over channel). 1147 // for sending messages over channel).
1148 // Additionally we have mock implementation ChromeFrameDelagate interface - 1148 // Additionally we have mock implementation ChromeFrameDelagate interface -
1149 // MockCFDelegate. 1149 // MockCFDelegate.
1150 1150
1151 // Test fixture, saves typing all of it's members. 1151 // Test fixture, saves typing all of it's members.
1152 class CFACMockTest : public testing::Test { 1152 class CFACMockTest : public testing::Test {
1153 public: 1153 public:
1154 MockProxyFactory factory_; 1154 MockProxyFactory factory_;
1155 MockCFDelegate cfd_; 1155 MockCFDelegate cfd_;
1156 TimedMsgLoop loop_; 1156 TimedMsgLoop loop_;
1157 MockAutomationProxy proxy_; 1157 MockAutomationProxy proxy_;
1158 scoped_ptr<AutomationHandleTracker> tracker_; 1158 scoped_ptr<AutomationHandleTracker> tracker_;
1159 MockAutomationMessageSender dummy_sender_; 1159 MockAutomationMessageSender dummy_sender_;
1160 scoped_refptr<TabProxy> tab_; 1160 scoped_refptr<TabProxy> tab_;
1161 scoped_ptr<ChromeFrameAutomationClient> client_; // the victim of all tests 1161 // the victim of all tests
1162 scoped_refptr<ChromeFrameAutomationClient> client_;
1162 1163
1163 std::wstring profile_; 1164 std::wstring profile_;
1164 int timeout_; 1165 int timeout_;
1165 void* id_; // Automation server id we are going to return 1166 void* id_; // Automation server id we are going to return
1166 int tab_handle_; // Tab handle. Any non-zero value is Ok. 1167 int tab_handle_; // Tab handle. Any non-zero value is Ok.
1167 1168
1168 inline ChromeFrameAutomationProxy* get_proxy() { 1169 inline ChromeFrameAutomationProxy* get_proxy() {
1169 return static_cast<ChromeFrameAutomationProxy*>(&proxy_); 1170 return static_cast<ChromeFrameAutomationProxy*>(&proxy_);
1170 } 1171 }
1171 1172
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
1203 CFACMockTest() : tracker_(NULL), timeout_(500), 1204 CFACMockTest() : tracker_(NULL), timeout_(500),
1204 profile_(L"Adam.N.Epilinter") { 1205 profile_(L"Adam.N.Epilinter") {
1205 id_ = reinterpret_cast<void*>(5); 1206 id_ = reinterpret_cast<void*>(5);
1206 tab_handle_ = 3; 1207 tab_handle_ = 3;
1207 } 1208 }
1208 1209
1209 virtual void SetUp() { 1210 virtual void SetUp() {
1210 dummy_sender_.ForwardTo(&proxy_); 1211 dummy_sender_.ForwardTo(&proxy_);
1211 tracker_.reset(new AutomationHandleTracker(&dummy_sender_)); 1212 tracker_.reset(new AutomationHandleTracker(&dummy_sender_));
1212 1213
1213 client_.reset(new ChromeFrameAutomationClient); 1214 client_ = new ChromeFrameAutomationClient;
1214 client_->set_proxy_factory(&factory_); 1215 client_->set_proxy_factory(&factory_);
1215 } 1216 }
1216 }; 1217 };
1217 1218
1218 // Could be implemented as MockAutomationProxy member (we have WithArgs<>!) 1219 // Could be implemented as MockAutomationProxy member (we have WithArgs<>!)
1219 ACTION_P3(HandleCreateTab, tab_handle, external_tab_container, tab_wnd) { 1220 ACTION_P3(HandleCreateTab, tab_handle, external_tab_container, tab_wnd) {
1220 // arg0 - message 1221 // arg0 - message
1221 // arg1 - callback 1222 // arg1 - callback
1222 // arg2 - key 1223 // arg2 - key
1223 CallbackRunner<Tuple3<HWND, HWND, int> >* c = 1224 CallbackRunner<Tuple3<HWND, HWND, int> >* c =
(...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after
1533 return; 1534 return;
1534 1535
1535 ASSERT_TRUE(mock.web_browser2() != NULL); 1536 ASSERT_TRUE(mock.web_browser2() != NULL);
1536 1537
1537 loop.RunFor(kChromeFrameLongNavigationTimeoutInSeconds); 1538 loop.RunFor(kChromeFrameLongNavigationTimeoutInSeconds);
1538 1539
1539 mock.Uninitialize(); 1540 mock.Uninitialize();
1540 chrome_frame_test::CloseAllIEWindows(); 1541 chrome_frame_test::CloseAllIEWindows();
1541 } 1542 }
1542 1543
OLDNEW
« no previous file with comments | « chrome_frame/test/chrome_frame_automation_mock.h ('k') | chrome_frame/urlmon_url_request.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698