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 22 matching lines...) Expand all Loading... |
33 | 33 |
34 #include "core/frame/Settings.h" | 34 #include "core/frame/Settings.h" |
35 #include "platform/RuntimeEnabledFeatures.h" | 35 #include "platform/RuntimeEnabledFeatures.h" |
36 #include "platform/scroll/ScrollbarTheme.h" | 36 #include "platform/scroll/ScrollbarTheme.h" |
37 #include "public/platform/WebURLRequest.h" | 37 #include "public/platform/WebURLRequest.h" |
38 #include "public/web/WebFrameClient.h" | 38 #include "public/web/WebFrameClient.h" |
39 #include "public/web/WebHistoryItem.h" | 39 #include "public/web/WebHistoryItem.h" |
40 #include "public/web/WebRemoteFrameClient.h" | 40 #include "public/web/WebRemoteFrameClient.h" |
41 #include "public/web/WebViewClient.h" | 41 #include "public/web/WebViewClient.h" |
42 #include "web/WebViewImpl.h" | 42 #include "web/WebViewImpl.h" |
43 #include "wtf/Allocator.h" | |
44 #include "wtf/PassOwnPtr.h" | 43 #include "wtf/PassOwnPtr.h" |
45 #include <gmock/gmock.h> | 44 #include <gmock/gmock.h> |
46 #include <gtest/gtest.h> | 45 #include <gtest/gtest.h> |
47 #include <string> | 46 #include <string> |
48 | 47 |
49 namespace blink { | 48 namespace blink { |
50 | 49 |
51 namespace FrameTestHelpers { | 50 namespace FrameTestHelpers { |
52 | 51 |
53 class TestWebFrameClient; | 52 class TestWebFrameClient; |
(...skipping 14 matching lines...) Expand all Loading... |
68 // this. Use one of the above helpers. | 67 // this. Use one of the above helpers. |
69 void pumpPendingRequestsDoNotUse(WebFrame*); | 68 void pumpPendingRequestsDoNotUse(WebFrame*); |
70 | 69 |
71 class SettingOverrider { | 70 class SettingOverrider { |
72 public: | 71 public: |
73 virtual void overrideSettings(WebSettings*) = 0; | 72 virtual void overrideSettings(WebSettings*) = 0; |
74 }; | 73 }; |
75 | 74 |
76 // Convenience class for handling the lifetime of a WebView and its associated m
ainframe in tests. | 75 // Convenience class for handling the lifetime of a WebView and its associated m
ainframe in tests. |
77 class WebViewHelper { | 76 class WebViewHelper { |
78 DISALLOW_ALLOCATION(); | |
79 WTF_MAKE_NONCOPYABLE(WebViewHelper); | 77 WTF_MAKE_NONCOPYABLE(WebViewHelper); |
80 public: | 78 public: |
81 WebViewHelper(SettingOverrider* = 0); | 79 WebViewHelper(SettingOverrider* = 0); |
82 ~WebViewHelper(); | 80 ~WebViewHelper(); |
83 | 81 |
84 // Creates and initializes the WebView. Implicitly calls reset() first. IF a | 82 // Creates and initializes the WebView. Implicitly calls reset() first. IF a |
85 // WebFrameClient or a WebViewClient are passed in, they must outlive the | 83 // WebFrameClient or a WebViewClient are passed in, they must outlive the |
86 // WebViewHelper. | 84 // WebViewHelper. |
87 WebViewImpl* initialize(bool enableJavascript = false, TestWebFrameClient* =
0, WebViewClient* = 0, void (*updateSettingsFunc)(WebSettings*) = 0); | 85 WebViewImpl* initialize(bool enableJavascript = false, TestWebFrameClient* =
0, WebViewClient* = 0, void (*updateSettingsFunc)(WebSettings*) = 0); |
88 | 86 |
89 // Same as initialize() but also performs the initial load of the url. Only | 87 // Same as initialize() but also performs the initial load of the url. Only |
90 // returns once the load is complete. | 88 // returns once the load is complete. |
91 WebViewImpl* initializeAndLoad(const std::string& url, bool enableJavascript
= false, TestWebFrameClient* = 0, WebViewClient* = 0, void (*updateSettingsFunc
)(WebSettings*) = 0); | 89 WebViewImpl* initializeAndLoad(const std::string& url, bool enableJavascript
= false, TestWebFrameClient* = 0, WebViewClient* = 0, void (*updateSettingsFunc
)(WebSettings*) = 0); |
92 | 90 |
93 void reset(); | 91 void reset(); |
94 | 92 |
95 WebView* webView() const { return m_webView; } | 93 WebView* webView() const { return m_webView; } |
96 WebViewImpl* webViewImpl() const { return m_webView; } | 94 WebViewImpl* webViewImpl() const { return m_webView; } |
97 | 95 |
98 private: | 96 private: |
99 WebViewImpl* m_webView; | 97 WebViewImpl* m_webView; |
100 SettingOverrider* m_settingOverrider; | 98 SettingOverrider* m_settingOverrider; |
101 }; | 99 }; |
102 | 100 |
103 // Minimal implementation of WebFrameClient needed for unit tests that load fram
es. Tests that load | 101 // Minimal implementation of WebFrameClient needed for unit tests that load fram
es. Tests that load |
104 // frames and need further specialization of WebFrameClient behavior should subc
lass this. | 102 // frames and need further specialization of WebFrameClient behavior should subc
lass this. |
105 class TestWebFrameClient : public WebFrameClient { | 103 class TestWebFrameClient : public WebFrameClient { |
106 WTF_MAKE_FAST_ALLOCATED(TestWebFrameClient); | |
107 public: | 104 public: |
108 TestWebFrameClient(); | 105 TestWebFrameClient(); |
109 | 106 |
110 WebFrame* createChildFrame(WebLocalFrame* parent, WebTreeScopeType, const We
bString& frameName, WebSandboxFlags) override; | 107 WebFrame* createChildFrame(WebLocalFrame* parent, WebTreeScopeType, const We
bString& frameName, WebSandboxFlags) override; |
111 void frameDetached(WebFrame*, DetachType) override; | 108 void frameDetached(WebFrame*, DetachType) override; |
112 void didStartLoading(bool) override; | 109 void didStartLoading(bool) override; |
113 void didStopLoading() override; | 110 void didStopLoading() override; |
114 | 111 |
115 bool isLoading() { return m_loadsInProgress > 0; } | 112 bool isLoading() { return m_loadsInProgress > 0; } |
116 void waitForLoadToComplete(); | 113 void waitForLoadToComplete(); |
117 | 114 |
118 private: | 115 private: |
119 int m_loadsInProgress; | 116 int m_loadsInProgress; |
120 }; | 117 }; |
121 | 118 |
122 // Minimal implementation of WebRemoteFrameClient needed for unit tests that loa
d remote frames. Tests that load | 119 // Minimal implementation of WebRemoteFrameClient needed for unit tests that loa
d remote frames. Tests that load |
123 // frames and need further specialization of WebFrameClient behavior should subc
lass this. | 120 // frames and need further specialization of WebFrameClient behavior should subc
lass this. |
124 class TestWebRemoteFrameClient : public WebRemoteFrameClient { | 121 class TestWebRemoteFrameClient : public WebRemoteFrameClient { |
125 DISALLOW_ALLOCATION(); | |
126 public: | 122 public: |
127 TestWebRemoteFrameClient(); | 123 TestWebRemoteFrameClient(); |
128 | 124 |
129 WebRemoteFrame* frame() const { return m_frame; } | 125 WebRemoteFrame* frame() const { return m_frame; } |
130 | 126 |
131 // WebRemoteFrameClient overrides: | 127 // WebRemoteFrameClient overrides: |
132 void frameDetached(DetachType) override; | 128 void frameDetached(DetachType) override; |
133 void postMessageEvent( | 129 void postMessageEvent( |
134 WebLocalFrame* sourceFrame, | 130 WebLocalFrame* sourceFrame, |
135 WebRemoteFrame* targetFrame, | 131 WebRemoteFrame* targetFrame, |
136 WebSecurityOrigin targetOrigin, | 132 WebSecurityOrigin targetOrigin, |
137 WebDOMMessageEvent) override { } | 133 WebDOMMessageEvent) override { } |
138 | 134 |
139 private: | 135 private: |
140 WebRemoteFrame* const m_frame; | 136 WebRemoteFrame* const m_frame; |
141 }; | 137 }; |
142 | 138 |
143 class TestWebViewClient : public WebViewClient { | 139 class TestWebViewClient : public WebViewClient { |
144 WTF_MAKE_FAST_ALLOCATED(TestWebViewClient); | |
145 public: | 140 public: |
146 virtual ~TestWebViewClient() { } | 141 virtual ~TestWebViewClient() { } |
147 void initializeLayerTreeView() override; | 142 void initializeLayerTreeView() override; |
148 WebLayerTreeView* layerTreeView() override { return m_layerTreeView.get(); } | 143 WebLayerTreeView* layerTreeView() override { return m_layerTreeView.get(); } |
149 | 144 |
150 private: | 145 private: |
151 OwnPtr<WebLayerTreeView> m_layerTreeView; | 146 OwnPtr<WebLayerTreeView> m_layerTreeView; |
152 }; | 147 }; |
153 | 148 |
154 class UseMockScrollbarSettings { | 149 class UseMockScrollbarSettings { |
155 DISALLOW_ALLOCATION(); | |
156 public: | 150 public: |
157 UseMockScrollbarSettings() | 151 UseMockScrollbarSettings() |
158 { | 152 { |
159 Settings::setMockScrollbarsEnabled(true); | 153 Settings::setMockScrollbarsEnabled(true); |
160 RuntimeEnabledFeatures::setOverlayScrollbarsEnabled(true); | 154 RuntimeEnabledFeatures::setOverlayScrollbarsEnabled(true); |
161 EXPECT_TRUE(ScrollbarTheme::theme()->usesOverlayScrollbars()); | 155 EXPECT_TRUE(ScrollbarTheme::theme()->usesOverlayScrollbars()); |
162 } | 156 } |
163 | 157 |
164 ~UseMockScrollbarSettings() | 158 ~UseMockScrollbarSettings() |
165 { | 159 { |
166 Settings::setMockScrollbarsEnabled(false); | 160 Settings::setMockScrollbarsEnabled(false); |
167 RuntimeEnabledFeatures::setOverlayScrollbarsEnabled(false); | 161 RuntimeEnabledFeatures::setOverlayScrollbarsEnabled(false); |
168 } | 162 } |
169 }; | 163 }; |
170 | 164 |
171 } // namespace FrameTestHelpers | 165 } // namespace FrameTestHelpers |
172 } // namespace blink | 166 } // namespace blink |
173 | 167 |
174 #endif // FrameTestHelpers_h | 168 #endif // FrameTestHelpers_h |
OLD | NEW |