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

Side by Side Diff: chrome_frame/test/net/test_automation_provider.cc

Issue 218019: Initial import of the Chrome Frame codebase. Integration in chrome.gyp coming... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 11 years, 2 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
(Empty)
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome_frame/test/net/test_automation_provider.h"
6
7 #include "base/command_line.h"
8 #include "chrome/test/automation/automation_messages.h"
9
10 #include "chrome_frame/test/net/test_automation_resource_message_filter.h"
11
12 namespace {
13
14 // A special command line switch to just run the unit tests without CF in
15 // the picture. Can be useful when the harness itself needs to be debugged.
16 const wchar_t kNoCfTestRun[] = L"no-cf-test-run";
17
18 bool CFTestsDisabled() {
19 static bool switch_present = CommandLine::ForCurrentProcess()->
20 HasSwitch(kNoCfTestRun);
21 return switch_present;
22 }
23
24 } // end namespace
25
26 TestAutomationProvider::TestAutomationProvider(
27 Profile* profile,
28 TestAutomationProviderDelegate* delegate)
29 : AutomationProvider(profile), tab_handle_(-1), delegate_(delegate) {
30 filter_ = new TestAutomationResourceMessageFilter(this);
31 URLRequest::RegisterRequestInterceptor(this);
32 }
33
34 TestAutomationProvider::~TestAutomationProvider() {
35 URLRequest::UnregisterRequestInterceptor(this);
36 }
37
38 void TestAutomationProvider::OnMessageReceived(const IPC::Message& msg) {
39 if (filter_->OnMessageReceived(msg))
40 return; // Message handled by the filter.
41
42 __super::OnMessageReceived(msg);
43 }
44
45 // IPC override to grab the tab handle.
46 bool TestAutomationProvider::Send(IPC::Message* msg) {
47 if (msg->type() == AutomationMsg_TabLoaded::ID) {
48 DCHECK(tab_handle_ == -1) << "Currently only support one tab";
49 void* iter = NULL;
50 CHECK(msg->ReadInt(&iter, &tab_handle_));
51 DLOG(INFO) << "Got tab handle: " << tab_handle_;
52 DCHECK(tab_handle_ != -1 && tab_handle_ != 0);
53 delegate_->OnInitialTabLoaded();
54 }
55
56 return AutomationProvider::Send(msg);
57 }
58
59 URLRequestJob* TestAutomationProvider::MaybeIntercept(URLRequest* request) {
60 if (CFTestsDisabled())
61 return NULL;
62
63 if (request->url().SchemeIs("http") || request->url().SchemeIs("https")) {
64 // Only look at requests that don't have any user data.
65 // ResourceDispatcherHost uses the user data for requests that it manages.
66 // We don't want to mess with those.
67
68 // We could also check if the current thread is our TestUrlRequest thread
69 // and only intercept requests that belong to that thread.
70 if (request->GetUserData(NULL) == NULL) {
71 DCHECK(tab_handle_ != -1);
72 URLRequestAutomationJob* job = new URLRequestAutomationJob(request,
73 tab_handle_, filter_);
74 return job;
75 }
76 }
77
78 return NULL;
79 }
80
81 // static
82 TestAutomationProvider* TestAutomationProvider::NewAutomationProvider(
83 Profile* p, const std::string& channel,
84 TestAutomationProviderDelegate* delegate) {
85 TestAutomationProvider* automation = new TestAutomationProvider(p, delegate);
86 automation->ConnectToChannel(channel);
87 automation->SetExpectedTabCount(1);
88 return automation;
89 }
OLDNEW
« no previous file with comments | « chrome_frame/test/net/test_automation_provider.h ('k') | chrome_frame/test/net/test_automation_resource_message_filter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698