Chromium Code Reviews| 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 void SetCurrentInputEventForTest(const WebInputEvent* event) { |
| 47 WebViewImpl::current_input_event_ = event; | 48 WebViewBase::SetCurrentInputEventForTest(event); |
|
sashab
2017/05/03 04:34:18
Maybe next time do this in a separate patch so its
slangley
2017/05/04 09:15:34
Will keep it in mind.
| |
| 48 } | 49 } |
| 49 | 50 |
| 50 namespace { | 51 namespace { |
| 51 | 52 |
| 52 class TestWebViewClient : public FrameTestHelpers::TestWebViewClient { | 53 class TestWebViewClient : public FrameTestHelpers::TestWebViewClient { |
| 53 public: | 54 public: |
| 54 explicit TestWebViewClient(WebNavigationPolicy* target) : target_(target) {} | 55 explicit TestWebViewClient(WebNavigationPolicy* target) : target_(target) {} |
| 55 ~TestWebViewClient() override {} | 56 ~TestWebViewClient() override {} |
| 56 | 57 |
| 57 void Show(WebNavigationPolicy policy) override { *target_ = policy; } | 58 void Show(WebNavigationPolicy policy) override { *target_ = policy; } |
| 58 | 59 |
| 59 private: | 60 private: |
| 60 WebNavigationPolicy* target_; | 61 WebNavigationPolicy* target_; |
| 61 }; | 62 }; |
| 62 | 63 |
| 63 } // anonymous namespace | 64 } // anonymous namespace |
| 64 | 65 |
| 65 class GetNavigationPolicyTest : public testing::Test { | 66 class GetNavigationPolicyTest : public testing::Test { |
| 66 public: | 67 public: |
| 67 GetNavigationPolicyTest() | 68 GetNavigationPolicyTest() |
| 68 : result_(kWebNavigationPolicyIgnore), web_view_client_(&result_) {} | 69 : result_(kWebNavigationPolicyIgnore), web_view_client_(&result_) {} |
| 69 | 70 |
| 70 protected: | 71 protected: |
| 71 void SetUp() override { | 72 void SetUp() override { |
| 72 web_view_ = ToWebViewImpl( | 73 web_view_ = |
| 73 WebView::Create(&web_view_client_, kWebPageVisibilityStateVisible)); | 74 WebViewBase::Create(&web_view_client_, kWebPageVisibilityStateVisible); |
| 74 web_view_->SetMainFrame(WebLocalFrame::Create( | 75 web_view_->SetMainFrame(WebLocalFrame::Create( |
| 75 WebTreeScopeType::kDocument, &web_frame_client_, nullptr, nullptr)); | 76 WebTreeScopeType::kDocument, &web_frame_client_, nullptr, nullptr)); |
| 76 chrome_client_impl_ = | 77 chrome_client_impl_ = |
| 77 ToChromeClientImpl(&web_view_->GetPage()->GetChromeClient()); | 78 ToChromeClientImpl(&web_view_->GetPage()->GetChromeClient()); |
| 78 result_ = kWebNavigationPolicyIgnore; | 79 result_ = kWebNavigationPolicyIgnore; |
| 79 } | 80 } |
| 80 | 81 |
| 81 void TearDown() override { web_view_->Close(); } | 82 void TearDown() override { web_view_->Close(); } |
| 82 | 83 |
| 83 WebNavigationPolicy GetNavigationPolicyWithMouseEvent( | 84 WebNavigationPolicy GetNavigationPolicyWithMouseEvent( |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 95 } | 96 } |
| 96 | 97 |
| 97 bool IsNavigationPolicyPopup() { | 98 bool IsNavigationPolicyPopup() { |
| 98 chrome_client_impl_->Show(kNavigationPolicyIgnore); | 99 chrome_client_impl_->Show(kNavigationPolicyIgnore); |
| 99 return result_ == kWebNavigationPolicyNewPopup; | 100 return result_ == kWebNavigationPolicyNewPopup; |
| 100 } | 101 } |
| 101 | 102 |
| 102 protected: | 103 protected: |
| 103 WebNavigationPolicy result_; | 104 WebNavigationPolicy result_; |
| 104 TestWebViewClient web_view_client_; | 105 TestWebViewClient web_view_client_; |
| 105 WebViewImpl* web_view_; | 106 WebViewBase* web_view_; |
| 106 FrameTestHelpers::TestWebFrameClient web_frame_client_; | 107 FrameTestHelpers::TestWebFrameClient web_frame_client_; |
| 107 Persistent<ChromeClientImpl> chrome_client_impl_; | 108 Persistent<ChromeClientImpl> chrome_client_impl_; |
| 108 }; | 109 }; |
| 109 | 110 |
| 110 TEST_F(GetNavigationPolicyTest, LeftClick) { | 111 TEST_F(GetNavigationPolicyTest, LeftClick) { |
| 111 int modifiers = 0; | 112 int modifiers = 0; |
| 112 WebMouseEvent::Button button = WebMouseEvent::Button::kLeft; | 113 WebMouseEvent::Button button = WebMouseEvent::Button::kLeft; |
| 113 bool as_popup = false; | 114 bool as_popup = false; |
| 114 EXPECT_EQ(kWebNavigationPolicyNewForegroundTab, | 115 EXPECT_EQ(kWebNavigationPolicyNewForegroundTab, |
| 115 GetNavigationPolicyWithMouseEvent(modifiers, button, as_popup)); | 116 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); | 245 return web_view_helper_.InitializeWithOpener(opener, true); |
| 245 } | 246 } |
| 246 | 247 |
| 247 private: | 248 private: |
| 248 FrameTestHelpers::WebViewHelper web_view_helper_; | 249 FrameTestHelpers::WebViewHelper web_view_helper_; |
| 249 }; | 250 }; |
| 250 | 251 |
| 251 class CreateWindowTest : public testing::Test { | 252 class CreateWindowTest : public testing::Test { |
| 252 protected: | 253 protected: |
| 253 void SetUp() override { | 254 void SetUp() override { |
| 254 web_view_ = ToWebViewImpl( | 255 web_view_ = |
| 255 WebView::Create(&web_view_client_, kWebPageVisibilityStateVisible)); | 256 WebViewBase::Create(&web_view_client_, kWebPageVisibilityStateVisible); |
| 256 main_frame_ = WebLocalFrame::Create(WebTreeScopeType::kDocument, | 257 main_frame_ = WebLocalFrame::Create(WebTreeScopeType::kDocument, |
| 257 &web_frame_client_, nullptr, nullptr); | 258 &web_frame_client_, nullptr, nullptr); |
| 258 web_view_->SetMainFrame(main_frame_); | 259 web_view_->SetMainFrame(main_frame_); |
| 259 chrome_client_impl_ = | 260 chrome_client_impl_ = |
| 260 ToChromeClientImpl(&web_view_->GetPage()->GetChromeClient()); | 261 ToChromeClientImpl(&web_view_->GetPage()->GetChromeClient()); |
| 261 } | 262 } |
| 262 | 263 |
| 263 void TearDown() override { web_view_->Close(); } | 264 void TearDown() override { web_view_->Close(); } |
| 264 | 265 |
| 265 ViewCreatingClient web_view_client_; | 266 ViewCreatingClient web_view_client_; |
| 266 WebViewImpl* web_view_; | 267 WebViewBase* web_view_; |
| 267 WebLocalFrame* main_frame_; | 268 WebLocalFrame* main_frame_; |
| 268 FrameTestHelpers::TestWebFrameClient web_frame_client_; | 269 FrameTestHelpers::TestWebFrameClient web_frame_client_; |
| 269 Persistent<ChromeClientImpl> chrome_client_impl_; | 270 Persistent<ChromeClientImpl> chrome_client_impl_; |
| 270 }; | 271 }; |
| 271 | 272 |
| 272 TEST_F(CreateWindowTest, CreateWindowFromSuspendedPage) { | 273 TEST_F(CreateWindowTest, CreateWindowFromSuspendedPage) { |
| 273 ScopedPageSuspender suspender; | 274 ScopedPageSuspender suspender; |
| 274 LocalFrame* frame = ToWebLocalFrameImpl(main_frame_)->GetFrame(); | 275 LocalFrame* frame = ToWebLocalFrameImpl(main_frame_)->GetFrame(); |
| 275 FrameLoadRequest request(frame->GetDocument()); | 276 FrameLoadRequest request(frame->GetDocument()); |
| 276 WindowFeatures features; | 277 WindowFeatures features; |
| 277 EXPECT_EQ(nullptr, | 278 EXPECT_EQ(nullptr, |
| 278 chrome_client_impl_->CreateWindow( | 279 chrome_client_impl_->CreateWindow( |
| 279 frame, request, features, kNavigationPolicyNewForegroundTab)); | 280 frame, request, features, kNavigationPolicyNewForegroundTab)); |
| 280 } | 281 } |
| 281 | 282 |
| 282 } // namespace blink | 283 } // namespace blink |
| OLD | NEW |