| OLD | NEW | 
|---|
|  | (Empty) | 
| 1 // Copyright 2013 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 "content/shell/renderer/test_runner/TestInterfaces.h" |  | 
| 6 |  | 
| 7 #include <string> |  | 
| 8 |  | 
| 9 #include "base/logging.h" |  | 
| 10 #include "base/command_line.h" |  | 
| 11 #include "base/strings/stringprintf.h" |  | 
| 12 #include "content/shell/common/shell_switches.h" |  | 
| 13 #include "content/shell/renderer/test_runner/accessibility_controller.h" |  | 
| 14 #include "content/shell/renderer/test_runner/event_sender.h" |  | 
| 15 #include "content/shell/renderer/test_runner/gamepad_controller.h" |  | 
| 16 #include "content/shell/renderer/test_runner/text_input_controller.h" |  | 
| 17 #include "content/shell/renderer/test_runner/test_runner.h" |  | 
| 18 #include "content/shell/renderer/test_runner/web_test_proxy.h" |  | 
| 19 #include "third_party/WebKit/public/platform/WebString.h" |  | 
| 20 #include "third_party/WebKit/public/platform/WebURL.h" |  | 
| 21 #include "third_party/WebKit/public/web/WebCache.h" |  | 
| 22 #include "third_party/WebKit/public/web/WebKit.h" |  | 
| 23 #include "third_party/WebKit/public/web/WebRuntimeFeatures.h" |  | 
| 24 #include "third_party/WebKit/public/web/WebView.h" |  | 
| 25 |  | 
| 26 using namespace blink; |  | 
| 27 |  | 
| 28 namespace content { |  | 
| 29 |  | 
| 30 TestInterfaces::TestInterfaces() |  | 
| 31     : m_accessibilityController(new AccessibilityController()) |  | 
| 32     , m_eventSender(new EventSender(this)) |  | 
| 33     , m_gamepadController(new GamepadController()) |  | 
| 34     , m_textInputController(new TextInputController()) |  | 
| 35     , m_testRunner(new TestRunner(this)) |  | 
| 36     , m_delegate(0) |  | 
| 37 { |  | 
| 38     blink::setLayoutTestMode(true); |  | 
| 39     if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnableFontAntiali
     asing)) |  | 
| 40         blink::setFontAntialiasingEnabledForTest(true); |  | 
| 41 |  | 
| 42     // NOTE: please don't put feature specific enable flags here, |  | 
| 43     // instead add them to RuntimeEnabledFeatures.in |  | 
| 44 |  | 
| 45     resetAll(); |  | 
| 46 } |  | 
| 47 |  | 
| 48 TestInterfaces::~TestInterfaces() |  | 
| 49 { |  | 
| 50     m_accessibilityController->SetWebView(0); |  | 
| 51     m_eventSender->SetWebView(0); |  | 
| 52     // m_gamepadController doesn't depend on WebView. |  | 
| 53     m_textInputController->SetWebView(NULL); |  | 
| 54     m_testRunner->SetWebView(0, 0); |  | 
| 55 |  | 
| 56     m_accessibilityController->SetDelegate(0); |  | 
| 57     m_eventSender->SetDelegate(0); |  | 
| 58     m_gamepadController->SetDelegate(0); |  | 
| 59     // m_textInputController doesn't depend on WebTestDelegate. |  | 
| 60     m_testRunner->SetDelegate(0); |  | 
| 61 } |  | 
| 62 |  | 
| 63 void TestInterfaces::setWebView(WebView* webView, WebTestProxyBase* proxy) |  | 
| 64 { |  | 
| 65     m_proxy = proxy; |  | 
| 66     m_accessibilityController->SetWebView(webView); |  | 
| 67     m_eventSender->SetWebView(webView); |  | 
| 68     // m_gamepadController doesn't depend on WebView. |  | 
| 69     m_textInputController->SetWebView(webView); |  | 
| 70     m_testRunner->SetWebView(webView, proxy); |  | 
| 71 } |  | 
| 72 |  | 
| 73 void TestInterfaces::setDelegate(WebTestDelegate* delegate) |  | 
| 74 { |  | 
| 75     m_accessibilityController->SetDelegate(delegate); |  | 
| 76     m_eventSender->SetDelegate(delegate); |  | 
| 77     m_gamepadController->SetDelegate(delegate); |  | 
| 78     // m_textInputController doesn't depend on WebTestDelegate. |  | 
| 79     m_testRunner->SetDelegate(delegate); |  | 
| 80     m_delegate = delegate; |  | 
| 81 } |  | 
| 82 |  | 
| 83 void TestInterfaces::bindTo(WebFrame* frame) |  | 
| 84 { |  | 
| 85     m_accessibilityController->Install(frame); |  | 
| 86     m_eventSender->Install(frame); |  | 
| 87     m_gamepadController->Install(frame); |  | 
| 88     m_textInputController->Install(frame); |  | 
| 89     m_testRunner->Install(frame); |  | 
| 90 } |  | 
| 91 |  | 
| 92 void TestInterfaces::resetTestHelperControllers() |  | 
| 93 { |  | 
| 94     m_accessibilityController->Reset(); |  | 
| 95     m_eventSender->Reset(); |  | 
| 96     m_gamepadController->Reset(); |  | 
| 97     // m_textInputController doesn't have any state to reset. |  | 
| 98     WebCache::clear(); |  | 
| 99 } |  | 
| 100 |  | 
| 101 void TestInterfaces::resetAll() |  | 
| 102 { |  | 
| 103     resetTestHelperControllers(); |  | 
| 104     m_testRunner->Reset(); |  | 
| 105 } |  | 
| 106 |  | 
| 107 void TestInterfaces::setTestIsRunning(bool running) |  | 
| 108 { |  | 
| 109     m_testRunner->SetTestIsRunning(running); |  | 
| 110 } |  | 
| 111 |  | 
| 112 void TestInterfaces::configureForTestWithURL(const WebURL& testURL, bool generat
     ePixels) |  | 
| 113 { |  | 
| 114     std::string spec = GURL(testURL).spec(); |  | 
| 115     m_testRunner->setShouldGeneratePixelResults(generatePixels); |  | 
| 116     if (spec.find("loading/") != std::string::npos) |  | 
| 117         m_testRunner->setShouldDumpFrameLoadCallbacks(true); |  | 
| 118     if (spec.find("/dumpAsText/") != std::string::npos) { |  | 
| 119         m_testRunner->setShouldDumpAsText(true); |  | 
| 120         m_testRunner->setShouldGeneratePixelResults(false); |  | 
| 121     } |  | 
| 122     if (spec.find("/inspector/") != std::string::npos |  | 
| 123         || spec.find("/inspector-enabled/") != std::string::npos) |  | 
| 124         m_testRunner->clearDevToolsLocalStorage(); |  | 
| 125     if (spec.find("/inspector/") != std::string::npos) { |  | 
| 126         // Subfolder name determines default panel to open. |  | 
| 127         std::string settings = ""; |  | 
| 128         std::string test_path = spec.substr(spec.find("/inspector/") + 11); |  | 
| 129         size_t slash_index = test_path.find("/"); |  | 
| 130         if (slash_index != std::string::npos) { |  | 
| 131             settings = base::StringPrintf( |  | 
| 132                 "{\"lastActivePanel\":\"\\\"%s\\\"\"}", |  | 
| 133                 test_path.substr(0, slash_index).c_str()); |  | 
| 134         } |  | 
| 135         m_testRunner->showDevTools(settings, std::string()); |  | 
| 136     } |  | 
| 137     if (spec.find("/viewsource/") != std::string::npos) { |  | 
| 138         m_testRunner->setShouldEnableViewSource(true); |  | 
| 139         m_testRunner->setShouldGeneratePixelResults(false); |  | 
| 140         m_testRunner->setShouldDumpAsMarkup(true); |  | 
| 141     } |  | 
| 142 } |  | 
| 143 |  | 
| 144 void TestInterfaces::windowOpened(WebTestProxyBase* proxy) |  | 
| 145 { |  | 
| 146     m_windowList.push_back(proxy); |  | 
| 147 } |  | 
| 148 |  | 
| 149 void TestInterfaces::windowClosed(WebTestProxyBase* proxy) |  | 
| 150 { |  | 
| 151     std::vector<WebTestProxyBase*>::iterator pos = std::find(m_windowList.begin(
     ), m_windowList.end(), proxy); |  | 
| 152     if (pos == m_windowList.end()) { |  | 
| 153         NOTREACHED(); |  | 
| 154         return; |  | 
| 155     } |  | 
| 156     m_windowList.erase(pos); |  | 
| 157 } |  | 
| 158 |  | 
| 159 AccessibilityController* TestInterfaces::accessibilityController() |  | 
| 160 { |  | 
| 161     return m_accessibilityController.get(); |  | 
| 162 } |  | 
| 163 |  | 
| 164 EventSender* TestInterfaces::eventSender() |  | 
| 165 { |  | 
| 166     return m_eventSender.get(); |  | 
| 167 } |  | 
| 168 |  | 
| 169 TestRunner* TestInterfaces::testRunner() |  | 
| 170 { |  | 
| 171     return m_testRunner.get(); |  | 
| 172 } |  | 
| 173 |  | 
| 174 WebTestDelegate* TestInterfaces::delegate() |  | 
| 175 { |  | 
| 176     return m_delegate; |  | 
| 177 } |  | 
| 178 |  | 
| 179 WebTestProxyBase* TestInterfaces::proxy() |  | 
| 180 { |  | 
| 181     return m_proxy; |  | 
| 182 } |  | 
| 183 |  | 
| 184 const std::vector<WebTestProxyBase*>& TestInterfaces::windowList() |  | 
| 185 { |  | 
| 186     return m_windowList; |  | 
| 187 } |  | 
| 188 |  | 
| 189 WebThemeEngine* TestInterfaces::themeEngine() |  | 
| 190 { |  | 
| 191     if (!m_testRunner->UseMockTheme()) |  | 
| 192         return 0; |  | 
| 193 #if defined(__APPLE__) |  | 
| 194     if (!m_themeEngine.get()) |  | 
| 195         m_themeEngine.reset(new MockWebThemeEngineMac()); |  | 
| 196 #else |  | 
| 197     if (!m_themeEngine.get()) |  | 
| 198         m_themeEngine.reset(new MockWebThemeEngine()); |  | 
| 199 #endif |  | 
| 200     return m_themeEngine.get(); |  | 
| 201 } |  | 
| 202 |  | 
| 203 }  // namespace content |  | 
| OLD | NEW | 
|---|