OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2011 Google Inc. All rights reserved. | 2 * Copyright (C) 2011 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 30 matching lines...) Expand all Loading... | |
41 #include "public/platform/Platform.h" | 41 #include "public/platform/Platform.h" |
42 #include "public/platform/WebString.h" | 42 #include "public/platform/WebString.h" |
43 #include "public/platform/WebThread.h" | 43 #include "public/platform/WebThread.h" |
44 #include "public/platform/WebURLRequest.h" | 44 #include "public/platform/WebURLRequest.h" |
45 #include "public/platform/WebURLResponse.h" | 45 #include "public/platform/WebURLResponse.h" |
46 #include "public/platform/WebUnitTestSupport.h" | 46 #include "public/platform/WebUnitTestSupport.h" |
47 | 47 |
48 namespace WebKit { | 48 namespace WebKit { |
49 namespace FrameTestHelpers { | 49 namespace FrameTestHelpers { |
50 | 50 |
51 namespace { | |
52 | |
53 class QuitTask : public WebThread::Task { | |
54 public: | |
55 virtual void run() | |
56 { | |
57 Platform::current()->currentThread()->exitRunLoop(); | |
58 } | |
59 }; | |
60 | |
61 class TestWebFrameClient : public WebFrameClient { | |
62 }; | |
63 | |
64 WebFrameClient* defaultWebFrameClient() | |
65 { | |
66 DEFINE_STATIC_LOCAL(TestWebFrameClient, client, ()); | |
67 return &client; | |
68 } | |
69 | |
70 class WebViewHelperClient : public WebViewClient { | |
71 }; | |
72 | |
73 WebViewClient* defaultWebViewClient() | |
74 { | |
75 DEFINE_STATIC_LOCAL(WebViewHelperClient, client, ()); | |
76 return &client; | |
77 } | |
78 | |
79 } // namespace | |
80 | |
51 void loadFrame(WebFrame* frame, const std::string& url) | 81 void loadFrame(WebFrame* frame, const std::string& url) |
52 { | 82 { |
53 WebURLRequest urlRequest; | 83 WebURLRequest urlRequest; |
54 urlRequest.initialize(); | 84 urlRequest.initialize(); |
55 urlRequest.setURL(URLTestHelpers::toKURL(url)); | 85 urlRequest.setURL(URLTestHelpers::toKURL(url)); |
56 frame->loadRequest(urlRequest); | 86 frame->loadRequest(urlRequest); |
57 } | 87 } |
58 | 88 |
59 class TestWebFrameClient : public WebFrameClient { | |
60 }; | |
61 | |
62 static WebFrameClient* defaultWebFrameClient() | |
63 { | |
64 DEFINE_STATIC_LOCAL(TestWebFrameClient, client, ()); | |
65 return &client; | |
66 } | |
67 | |
68 class TestWebViewClient : public WebViewClient { | |
69 }; | |
70 | |
71 static WebViewClient* defaultWebViewClient() | |
72 { | |
73 DEFINE_STATIC_LOCAL(TestWebViewClient, client, ()); | |
74 return &client; | |
75 } | |
76 | |
77 WebView* createWebView(bool enableJavascript, WebFrameClient* webFrameClient, We bViewClient* webViewClient) | |
78 { | |
79 if (!webFrameClient) | |
80 webFrameClient = defaultWebFrameClient(); | |
81 if (!webViewClient) | |
82 webViewClient = defaultWebViewClient(); | |
83 WebView* webView = WebView::create(webViewClient); | |
84 webView->settings()->setJavaScriptEnabled(enableJavascript); | |
85 webView->settings()->setDeviceSupportsMouse(false); | |
86 webView->settings()->setForceCompositingMode(true); | |
87 webView->initializeMainFrame(webFrameClient); | |
88 | |
89 return webView; | |
90 } | |
91 | |
92 WebView* createWebViewAndLoad(const std::string& url, bool enableJavascript, Web FrameClient* webFrameClient, WebViewClient* webViewClient) | |
93 { | |
94 WebView* webView = createWebView(enableJavascript, webFrameClient, webViewCl ient); | |
95 | |
96 loadFrame(webView->mainFrame(), url); | |
97 Platform::current()->unitTestSupport()->serveAsynchronousMockedRequests(); | |
98 | |
99 return webView; | |
100 } | |
101 | |
102 class QuitTask : public WebThread::Task { | |
103 public: | |
104 virtual void run() | |
105 { | |
106 Platform::current()->currentThread()->exitRunLoop(); | |
107 } | |
108 }; | |
109 | |
110 void runPendingTasks() | 89 void runPendingTasks() |
111 { | 90 { |
112 Platform::current()->currentThread()->postTask(new QuitTask); | 91 Platform::current()->currentThread()->postTask(new QuitTask); |
113 Platform::current()->currentThread()->enterRunLoop(); | 92 Platform::current()->currentThread()->enterRunLoop(); |
114 } | 93 } |
115 | 94 |
95 WebViewHelper::WebViewHelper() | |
96 : m_mainFrame(0) | |
97 , m_webView(0) | |
98 { | |
99 } | |
100 | |
101 WebViewHelper::~WebViewHelper() | |
102 { | |
103 reset(); | |
104 } | |
105 | |
106 WebView* WebViewHelper::initialize(bool enableJavascript, WebFrameClient* webFra meClient, WebViewClient* webViewClient) | |
107 { | |
108 ASSERT(!m_webView); | |
109 ASSERT(!m_mainFrame); | |
110 | |
111 if (!webFrameClient) | |
112 webFrameClient = defaultWebFrameClient(); | |
113 if (!webViewClient) | |
114 webViewClient = defaultWebViewClient(); | |
115 m_mainFrame = WebFrame::create(webFrameClient); | |
darin (slow to review)
2013/09/13 04:02:47
nit: allocate m_mainFrame closer to where it is fi
awong
2013/09/18 22:04:47
Done.
| |
116 m_webView = WebView::create(webViewClient); | |
117 m_webView->settings()->setJavaScriptEnabled(enableJavascript); | |
118 m_webView->settings()->setDeviceSupportsMouse(false); | |
119 m_webView->settings()->setForceCompositingMode(true); | |
120 m_webView->initializeMainFrame(m_mainFrame); | |
121 | |
122 return m_webView; | |
123 } | |
124 | |
125 WebView* WebViewHelper::initializeAndLoad(const std::string& url, bool enableJav ascript, WebFrameClient* webFrameClient, WebViewClient* webViewClient) | |
126 { | |
127 ASSERT(!m_webView); | |
128 ASSERT(!m_mainFrame); | |
129 | |
130 initialize(enableJavascript, webFrameClient, webViewClient); | |
131 | |
132 loadFrame(webView()->mainFrame(), url); | |
133 Platform::current()->unitTestSupport()->serveAsynchronousMockedRequests(); | |
134 | |
135 return webView(); | |
136 } | |
137 | |
138 void WebViewHelper::reset() { | |
139 if (m_webView) | |
140 m_webView->close(); | |
141 if (m_mainFrame) | |
142 m_mainFrame->close(); | |
143 } | |
144 | |
116 } // namespace FrameTestHelpers | 145 } // namespace FrameTestHelpers |
117 } // namespace WebKit | 146 } // namespace WebKit |
OLD | NEW |