OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2012 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 20 matching lines...) Expand all Loading... | |
31 #include "core/exported/WebViewBase.h" | 31 #include "core/exported/WebViewBase.h" |
32 #include "core/loader/FrameLoadRequest.h" | 32 #include "core/loader/FrameLoadRequest.h" |
33 #include "core/page/Page.h" | 33 #include "core/page/Page.h" |
34 #include "core/page/ScopedPageSuspender.h" | 34 #include "core/page/ScopedPageSuspender.h" |
35 #include "public/platform/WebInputEvent.h" | 35 #include "public/platform/WebInputEvent.h" |
36 #include "public/web/WebFrameClient.h" | 36 #include "public/web/WebFrameClient.h" |
37 #include "public/web/WebLocalFrame.h" | 37 #include "public/web/WebLocalFrame.h" |
38 #include "public/web/WebView.h" | 38 #include "public/web/WebView.h" |
39 #include "public/web/WebViewClient.h" | 39 #include "public/web/WebViewClient.h" |
40 #include "testing/gtest/include/gtest/gtest.h" | 40 #include "testing/gtest/include/gtest/gtest.h" |
41 #include "web/ChromeClientImpl.h" | |
41 #include "web/WebLocalFrameImpl.h" | 42 #include "web/WebLocalFrameImpl.h" |
42 #include "web/tests/FrameTestHelpers.h" | 43 #include "web/tests/FrameTestHelpers.h" |
43 | 44 |
44 namespace blink { | 45 namespace blink { |
45 | 46 |
46 void SetCurrentInputEventForTest(const WebInputEvent* event) { | |
47 WebViewImpl::current_input_event_ = event; | |
48 } | |
49 | |
50 namespace { | 47 namespace { |
51 | 48 |
52 class TestWebViewClient : public FrameTestHelpers::TestWebViewClient { | 49 class TestWebViewClient : public FrameTestHelpers::TestWebViewClient { |
53 public: | 50 public: |
54 explicit TestWebViewClient(WebNavigationPolicy* target) : target_(target) {} | 51 explicit TestWebViewClient(WebNavigationPolicy* target) : target_(target) {} |
55 ~TestWebViewClient() override {} | 52 ~TestWebViewClient() override {} |
56 | 53 |
57 void Show(WebNavigationPolicy policy) override { *target_ = policy; } | 54 void Show(WebNavigationPolicy policy) override { *target_ = policy; } |
58 | 55 |
59 private: | 56 private: |
60 WebNavigationPolicy* target_; | 57 WebNavigationPolicy* target_; |
61 }; | 58 }; |
62 | 59 |
63 } // anonymous namespace | 60 } // anonymous namespace |
64 | 61 |
65 class GetNavigationPolicyTest : public testing::Test { | 62 class GetNavigationPolicyTest : public testing::Test { |
66 public: | 63 public: |
67 GetNavigationPolicyTest() | 64 GetNavigationPolicyTest() |
68 : result_(kWebNavigationPolicyIgnore), web_view_client_(&result_) {} | 65 : result_(kWebNavigationPolicyIgnore), web_view_client_(&result_) {} |
69 | 66 |
70 protected: | 67 protected: |
71 void SetUp() override { | 68 void SetUp() override { |
72 web_view_ = ToWebViewImpl( | 69 web_view_ = static_cast<WebViewBase*>( |
73 WebView::Create(&web_view_client_, kWebPageVisibilityStateVisible)); | 70 WebViewBase::Create(&web_view_client_, kWebPageVisibilityStateVisible)); |
74 web_view_->SetMainFrame(WebLocalFrame::Create( | 71 web_view_->SetMainFrame(WebLocalFrame::Create( |
75 WebTreeScopeType::kDocument, &web_frame_client_, nullptr, nullptr)); | 72 WebTreeScopeType::kDocument, &web_frame_client_, nullptr, nullptr)); |
76 chrome_client_impl_ = | 73 chrome_client_impl_ = |
77 ToChromeClientImpl(&web_view_->GetPage()->GetChromeClient()); | 74 ToChromeClientImpl(&web_view_->GetPage()->GetChromeClient()); |
78 result_ = kWebNavigationPolicyIgnore; | 75 result_ = kWebNavigationPolicyIgnore; |
79 } | 76 } |
80 | 77 |
81 void TearDown() override { web_view_->Close(); } | 78 void TearDown() override { web_view_->Close(); } |
82 | 79 |
83 WebNavigationPolicy GetNavigationPolicyWithMouseEvent( | 80 WebNavigationPolicy GetNavigationPolicyWithMouseEvent( |
84 int modifiers, | 81 int modifiers, |
85 WebMouseEvent::Button button, | 82 WebMouseEvent::Button button, |
86 bool as_popup) { | 83 bool as_popup) { |
87 WebMouseEvent event(WebInputEvent::kMouseUp, modifiers, | 84 WebMouseEvent event(WebInputEvent::kMouseUp, modifiers, |
88 WebInputEvent::kTimeStampForTesting); | 85 WebInputEvent::kTimeStampForTesting); |
89 event.button = button; | 86 event.button = button; |
90 SetCurrentInputEventForTest(&event); | 87 web_view_->SetCurrentInputEventForTest(&event); |
91 chrome_client_impl_->SetToolbarsVisible(!as_popup); | 88 chrome_client_impl_->SetToolbarsVisible(!as_popup); |
92 chrome_client_impl_->Show(kNavigationPolicyIgnore); | 89 chrome_client_impl_->Show(kNavigationPolicyIgnore); |
93 SetCurrentInputEventForTest(0); | 90 web_view_->SetCurrentInputEventForTest(0); |
94 return result_; | 91 return result_; |
95 } | 92 } |
96 | 93 |
97 bool IsNavigationPolicyPopup() { | 94 bool IsNavigationPolicyPopup() { |
98 chrome_client_impl_->Show(kNavigationPolicyIgnore); | 95 chrome_client_impl_->Show(kNavigationPolicyIgnore); |
99 return result_ == kWebNavigationPolicyNewPopup; | 96 return result_ == kWebNavigationPolicyNewPopup; |
100 } | 97 } |
101 | 98 |
102 protected: | 99 protected: |
103 WebNavigationPolicy result_; | 100 WebNavigationPolicy result_; |
104 TestWebViewClient web_view_client_; | 101 TestWebViewClient web_view_client_; |
105 WebViewImpl* web_view_; | 102 WebViewBase* web_view_; |
106 FrameTestHelpers::TestWebFrameClient web_frame_client_; | 103 FrameTestHelpers::TestWebFrameClient web_frame_client_; |
107 Persistent<ChromeClientImpl> chrome_client_impl_; | 104 Persistent<ChromeClientImpl> chrome_client_impl_; |
108 }; | 105 }; |
109 | 106 |
110 TEST_F(GetNavigationPolicyTest, LeftClick) { | 107 TEST_F(GetNavigationPolicyTest, LeftClick) { |
111 int modifiers = 0; | 108 int modifiers = 0; |
112 WebMouseEvent::Button button = WebMouseEvent::Button::kLeft; | 109 WebMouseEvent::Button button = WebMouseEvent::Button::kLeft; |
113 bool as_popup = false; | 110 bool as_popup = false; |
114 EXPECT_EQ(kWebNavigationPolicyNewForegroundTab, | 111 EXPECT_EQ(kWebNavigationPolicyNewForegroundTab, |
115 GetNavigationPolicyWithMouseEvent(modifiers, button, as_popup)); | 112 GetNavigationPolicyWithMouseEvent(modifiers, button, as_popup)); |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
244 return web_view_helper_.InitializeWithOpener(opener, true); | 241 return web_view_helper_.InitializeWithOpener(opener, true); |
245 } | 242 } |
246 | 243 |
247 private: | 244 private: |
248 FrameTestHelpers::WebViewHelper web_view_helper_; | 245 FrameTestHelpers::WebViewHelper web_view_helper_; |
249 }; | 246 }; |
250 | 247 |
251 class CreateWindowTest : public testing::Test { | 248 class CreateWindowTest : public testing::Test { |
252 protected: | 249 protected: |
253 void SetUp() override { | 250 void SetUp() override { |
254 web_view_ = ToWebViewImpl( | 251 web_view_ = static_cast<WebViewBase*>( |
255 WebView::Create(&web_view_client_, kWebPageVisibilityStateVisible)); | 252 WebViewBase::Create(&web_view_client_, kWebPageVisibilityStateVisible)); |
dcheng
2017/05/29 10:09:19
Btw I just came across this and found it a little
| |
256 main_frame_ = WebLocalFrame::Create(WebTreeScopeType::kDocument, | 253 main_frame_ = WebLocalFrame::Create(WebTreeScopeType::kDocument, |
257 &web_frame_client_, nullptr, nullptr); | 254 &web_frame_client_, nullptr, nullptr); |
258 web_view_->SetMainFrame(main_frame_); | 255 web_view_->SetMainFrame(main_frame_); |
259 chrome_client_impl_ = | 256 chrome_client_impl_ = |
260 ToChromeClientImpl(&web_view_->GetPage()->GetChromeClient()); | 257 ToChromeClientImpl(&web_view_->GetPage()->GetChromeClient()); |
261 } | 258 } |
262 | 259 |
263 void TearDown() override { web_view_->Close(); } | 260 void TearDown() override { web_view_->Close(); } |
264 | 261 |
265 ViewCreatingClient web_view_client_; | 262 ViewCreatingClient web_view_client_; |
266 WebViewImpl* web_view_; | 263 WebViewBase* web_view_; |
267 WebLocalFrame* main_frame_; | 264 WebLocalFrame* main_frame_; |
268 FrameTestHelpers::TestWebFrameClient web_frame_client_; | 265 FrameTestHelpers::TestWebFrameClient web_frame_client_; |
269 Persistent<ChromeClientImpl> chrome_client_impl_; | 266 Persistent<ChromeClientImpl> chrome_client_impl_; |
270 }; | 267 }; |
271 | 268 |
272 TEST_F(CreateWindowTest, CreateWindowFromSuspendedPage) { | 269 TEST_F(CreateWindowTest, CreateWindowFromSuspendedPage) { |
273 ScopedPageSuspender suspender; | 270 ScopedPageSuspender suspender; |
274 LocalFrame* frame = ToWebLocalFrameImpl(main_frame_)->GetFrame(); | 271 LocalFrame* frame = ToWebLocalFrameImpl(main_frame_)->GetFrame(); |
275 FrameLoadRequest request(frame->GetDocument()); | 272 FrameLoadRequest request(frame->GetDocument()); |
276 WindowFeatures features; | 273 WindowFeatures features; |
277 EXPECT_EQ(nullptr, | 274 EXPECT_EQ(nullptr, |
278 chrome_client_impl_->CreateWindow( | 275 chrome_client_impl_->CreateWindow( |
279 frame, request, features, kNavigationPolicyNewForegroundTab)); | 276 frame, request, features, kNavigationPolicyNewForegroundTab)); |
280 } | 277 } |
281 | 278 |
282 } // namespace blink | 279 } // namespace blink |
OLD | NEW |