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

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

Issue 15935013: chrome_frame: Use base::MessageLoop. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix license Created 7 years, 6 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
« no previous file with comments | « chrome_frame/test/test_server.cc ('k') | chrome_frame/test/urlmon_moniker_integration_test.cc » ('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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 <windows.h> 5 #include <windows.h>
6 #include <wininet.h> 6 #include <wininet.h>
7 7
8 #include "base/basictypes.h" 8 #include "base/basictypes.h"
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/path_service.h" 10 #include "base/path_service.h"
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 72
73 class UrlTaskChain { 73 class UrlTaskChain {
74 public: 74 public:
75 UrlTaskChain(const std::string& url, UrlTaskChain* next) 75 UrlTaskChain(const std::string& url, UrlTaskChain* next)
76 : url_(url), next_(next) { 76 : url_(url), next_(next) {
77 } 77 }
78 78
79 void Run() { 79 void Run() {
80 EXPECT_EQ(0, delegate_.response_started_count()); 80 EXPECT_EQ(0, delegate_.response_started_count());
81 81
82 MessageLoopForIO loop; 82 base::MessageLoopForIO loop;
83 83
84 net::TestURLRequestContext context; 84 net::TestURLRequestContext context;
85 TestURLRequest r(GURL(url_), &delegate_, &context); 85 TestURLRequest r(GURL(url_), &delegate_, &context);
86 r.Start(); 86 r.Start();
87 EXPECT_TRUE(r.is_pending()); 87 EXPECT_TRUE(r.is_pending());
88 88
89 MessageLoop::current()->Run(); 89 base::MessageLoop::current()->Run();
90 90
91 EXPECT_EQ(1, delegate_.response_started_count()); 91 EXPECT_EQ(1, delegate_.response_started_count());
92 EXPECT_FALSE(delegate_.received_data_before_response()); 92 EXPECT_FALSE(delegate_.received_data_before_response());
93 EXPECT_NE(0, delegate_.bytes_received()); 93 EXPECT_NE(0, delegate_.bytes_received());
94 } 94 }
95 95
96 UrlTaskChain* next() const { 96 UrlTaskChain* next() const {
97 return next_; 97 return next_;
98 } 98 }
99 99
(...skipping 11 matching lines...) Expand all
111 UrlTaskChain* task = reinterpret_cast<UrlTaskChain*>(param); 111 UrlTaskChain* task = reinterpret_cast<UrlTaskChain*>(param);
112 while (task != NULL) { 112 while (task != NULL) {
113 task->Run(); 113 task->Run();
114 task = task->next(); 114 task = task->next();
115 } 115 }
116 116
117 return 0; 117 return 0;
118 } 118 }
119 119
120 struct QuitMessageHit { 120 struct QuitMessageHit {
121 explicit QuitMessageHit(MessageLoopForUI* loop) : loop_(loop), hit_(false) { 121 explicit QuitMessageHit(base::MessageLoopForUI* loop)
122 } 122 : loop_(loop), hit_(false) {}
123 123
124 MessageLoopForUI* loop_; 124 base::MessageLoopForUI* loop_;
125 bool hit_; 125 bool hit_;
126 }; 126 };
127 127
128 void QuitMessageLoop(QuitMessageHit* msg) { 128 void QuitMessageLoop(QuitMessageHit* msg) {
129 msg->hit_ = true; 129 msg->hit_ = true;
130 msg->loop_->PostTask(FROM_HERE, MessageLoop::QuitClosure()); 130 msg->loop_->PostTask(FROM_HERE, base::MessageLoop::QuitClosure());
131 } 131 }
132 132
133 } // end namespace 133 } // end namespace
134 134
135 TEST_F(TestServerTest, TestServer) { 135 TEST_F(TestServerTest, TestServer) {
136 // The web server needs a loop to exist on this thread during construction 136 // The web server needs a loop to exist on this thread during construction
137 // the loop must be created before we construct the server. 137 // the loop must be created before we construct the server.
138 MessageLoopForUI loop; 138 base::MessageLoopForUI loop;
139 139
140 test_server::SimpleWebServer server(1337); 140 test_server::SimpleWebServer server(1337);
141 test_server::SimpleWebServer redirected_server(server.host(), 1338); 141 test_server::SimpleWebServer redirected_server(server.host(), 1338);
142 test_server::SimpleResponse person("/person", "Guthrie Govan!"); 142 test_server::SimpleResponse person("/person", "Guthrie Govan!");
143 server.AddResponse(&person); 143 server.AddResponse(&person);
144 test_server::FileResponse file("/file", source_path().Append( 144 test_server::FileResponse file("/file", source_path().Append(
145 FILE_PATH_LITERAL("CFInstance.js"))); 145 FILE_PATH_LITERAL("CFInstance.js")));
146 server.AddResponse(&file); 146 server.AddResponse(&file);
147 test_server::RedirectResponse redir( 147 test_server::RedirectResponse redir(
148 "/redir", 148 "/redir",
(...skipping 21 matching lines...) Expand all
170 UrlTaskChain file_task( 170 UrlTaskChain file_task(
171 base::StringPrintf("http://%s:1337/file", server.host().c_str()), 171 base::StringPrintf("http://%s:1337/file", server.host().c_str()),
172 &person_task); 172 &person_task);
173 UrlTaskChain redir_task( 173 UrlTaskChain redir_task(
174 base::StringPrintf("http://%s:1337/redir", server.host().c_str()), 174 base::StringPrintf("http://%s:1337/redir", server.host().c_str()),
175 &file_task); 175 &file_task);
176 176
177 DWORD tid = 0; 177 DWORD tid = 0;
178 base::win::ScopedHandle worker(::CreateThread( 178 base::win::ScopedHandle worker(::CreateThread(
179 NULL, 0, FetchUrl, &redir_task, 0, &tid)); 179 NULL, 0, FetchUrl, &redir_task, 0, &tid));
180 loop.MessageLoop::Run(); 180 loop.base::MessageLoop::Run();
181 181
182 EXPECT_FALSE(quit_msg.hit_); 182 EXPECT_FALSE(quit_msg.hit_);
183 if (!quit_msg.hit_) { 183 if (!quit_msg.hit_) {
184 EXPECT_EQ(::WaitForSingleObject(worker, 10 * 1000), WAIT_OBJECT_0); 184 EXPECT_EQ(::WaitForSingleObject(worker, 10 * 1000), WAIT_OBJECT_0);
185 185
186 EXPECT_EQ(person.accessed(), 1); 186 EXPECT_EQ(person.accessed(), 1);
187 EXPECT_EQ(file.accessed(), 1); 187 EXPECT_EQ(file.accessed(), 1);
188 EXPECT_EQ(redir.accessed(), 1); 188 EXPECT_EQ(redir.accessed(), 1);
189 189
190 EXPECT_TRUE(person_task.response().find("Guthrie") != std::string::npos); 190 EXPECT_TRUE(person_task.response().find("Guthrie") != std::string::npos);
191 EXPECT_TRUE(file_task.response().find("function") != std::string::npos); 191 EXPECT_TRUE(file_task.response().find("function") != std::string::npos);
192 EXPECT_TRUE(redir_task.response().find("Destination") != std::string::npos); 192 EXPECT_TRUE(redir_task.response().find("Destination") != std::string::npos);
193 } else { 193 } else {
194 ::TerminateThread(worker, ~0); 194 ::TerminateThread(worker, ~0);
195 } 195 }
196 } 196 }
OLDNEW
« no previous file with comments | « chrome_frame/test/test_server.cc ('k') | chrome_frame/test/urlmon_moniker_integration_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698