| 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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 ~TestWebViewClient() override {} | 57 ~TestWebViewClient() override {} |
| 58 | 58 |
| 59 void Show(WebNavigationPolicy policy) override { *target_ = policy; } | 59 void Show(WebNavigationPolicy policy) override { *target_ = policy; } |
| 60 | 60 |
| 61 private: | 61 private: |
| 62 WebNavigationPolicy* target_; | 62 WebNavigationPolicy* target_; |
| 63 }; | 63 }; |
| 64 | 64 |
| 65 } // anonymous namespace | 65 } // anonymous namespace |
| 66 | 66 |
| 67 class GetNavigationPolicyTest : public testing::Test { | |
| 68 public: | |
| 69 GetNavigationPolicyTest() | |
| 70 : result_(kWebNavigationPolicyIgnore), web_view_client_(&result_) {} | |
| 71 | |
| 72 protected: | |
| 73 void SetUp() override { | |
| 74 web_view_ = static_cast<WebViewBase*>( | |
| 75 WebViewBase::Create(&web_view_client_, kWebPageVisibilityStateVisible)); | |
| 76 web_view_->SetMainFrame(WebLocalFrame::Create( | |
| 77 WebTreeScopeType::kDocument, &web_frame_client_, nullptr, nullptr)); | |
| 78 chrome_client_impl_ = | |
| 79 ToChromeClientImpl(&web_view_->GetPage()->GetChromeClient()); | |
| 80 result_ = kWebNavigationPolicyIgnore; | |
| 81 } | |
| 82 | |
| 83 void TearDown() override { web_view_->Close(); } | |
| 84 | |
| 85 WebNavigationPolicy GetNavigationPolicyWithMouseEvent( | |
| 86 int modifiers, | |
| 87 WebMouseEvent::Button button, | |
| 88 bool as_popup) { | |
| 89 WebMouseEvent event(WebInputEvent::kMouseUp, modifiers, | |
| 90 WebInputEvent::kTimeStampForTesting); | |
| 91 event.button = button; | |
| 92 web_view_->SetCurrentInputEventForTest(&event); | |
| 93 chrome_client_impl_->SetToolbarsVisible(!as_popup); | |
| 94 chrome_client_impl_->Show(kNavigationPolicyIgnore); | |
| 95 web_view_->SetCurrentInputEventForTest(0); | |
| 96 return result_; | |
| 97 } | |
| 98 | |
| 99 bool IsNavigationPolicyPopup() { | |
| 100 chrome_client_impl_->Show(kNavigationPolicyIgnore); | |
| 101 return result_ == kWebNavigationPolicyNewPopup; | |
| 102 } | |
| 103 | |
| 104 protected: | |
| 105 WebNavigationPolicy result_; | |
| 106 TestWebViewClient web_view_client_; | |
| 107 WebViewBase* web_view_; | |
| 108 FrameTestHelpers::TestWebFrameClient web_frame_client_; | |
| 109 Persistent<ChromeClientImpl> chrome_client_impl_; | |
| 110 }; | |
| 111 | |
| 112 TEST_F(GetNavigationPolicyTest, LeftClick) { | |
| 113 int modifiers = 0; | |
| 114 WebMouseEvent::Button button = WebMouseEvent::Button::kLeft; | |
| 115 bool as_popup = false; | |
| 116 EXPECT_EQ(kWebNavigationPolicyNewForegroundTab, | |
| 117 GetNavigationPolicyWithMouseEvent(modifiers, button, as_popup)); | |
| 118 } | |
| 119 | |
| 120 TEST_F(GetNavigationPolicyTest, LeftClickPopup) { | |
| 121 int modifiers = 0; | |
| 122 WebMouseEvent::Button button = WebMouseEvent::Button::kLeft; | |
| 123 bool as_popup = true; | |
| 124 EXPECT_EQ(kWebNavigationPolicyNewPopup, | |
| 125 GetNavigationPolicyWithMouseEvent(modifiers, button, as_popup)); | |
| 126 } | |
| 127 | |
| 128 TEST_F(GetNavigationPolicyTest, ShiftLeftClick) { | |
| 129 int modifiers = WebInputEvent::kShiftKey; | |
| 130 WebMouseEvent::Button button = WebMouseEvent::Button::kLeft; | |
| 131 bool as_popup = false; | |
| 132 EXPECT_EQ(kWebNavigationPolicyNewWindow, | |
| 133 GetNavigationPolicyWithMouseEvent(modifiers, button, as_popup)); | |
| 134 } | |
| 135 | |
| 136 TEST_F(GetNavigationPolicyTest, ShiftLeftClickPopup) { | |
| 137 int modifiers = WebInputEvent::kShiftKey; | |
| 138 WebMouseEvent::Button button = WebMouseEvent::Button::kLeft; | |
| 139 bool as_popup = true; | |
| 140 EXPECT_EQ(kWebNavigationPolicyNewPopup, | |
| 141 GetNavigationPolicyWithMouseEvent(modifiers, button, as_popup)); | |
| 142 } | |
| 143 | |
| 144 TEST_F(GetNavigationPolicyTest, ControlOrMetaLeftClick) { | |
| 145 #if OS(MACOSX) | |
| 146 int modifiers = WebInputEvent::kMetaKey; | |
| 147 #else | |
| 148 int modifiers = WebInputEvent::kControlKey; | |
| 149 #endif | |
| 150 WebMouseEvent::Button button = WebMouseEvent::Button::kLeft; | |
| 151 bool as_popup = false; | |
| 152 EXPECT_EQ(kWebNavigationPolicyNewBackgroundTab, | |
| 153 GetNavigationPolicyWithMouseEvent(modifiers, button, as_popup)); | |
| 154 } | |
| 155 | |
| 156 TEST_F(GetNavigationPolicyTest, ControlOrMetaLeftClickPopup) { | |
| 157 #if OS(MACOSX) | |
| 158 int modifiers = WebInputEvent::kMetaKey; | |
| 159 #else | |
| 160 int modifiers = WebInputEvent::kControlKey; | |
| 161 #endif | |
| 162 WebMouseEvent::Button button = WebMouseEvent::Button::kLeft; | |
| 163 bool as_popup = true; | |
| 164 EXPECT_EQ(kWebNavigationPolicyNewBackgroundTab, | |
| 165 GetNavigationPolicyWithMouseEvent(modifiers, button, as_popup)); | |
| 166 } | |
| 167 | |
| 168 TEST_F(GetNavigationPolicyTest, ControlOrMetaAndShiftLeftClick) { | |
| 169 #if OS(MACOSX) | |
| 170 int modifiers = WebInputEvent::kMetaKey; | |
| 171 #else | |
| 172 int modifiers = WebInputEvent::kControlKey; | |
| 173 #endif | |
| 174 modifiers |= WebInputEvent::kShiftKey; | |
| 175 WebMouseEvent::Button button = WebMouseEvent::Button::kLeft; | |
| 176 bool as_popup = false; | |
| 177 EXPECT_EQ(kWebNavigationPolicyNewForegroundTab, | |
| 178 GetNavigationPolicyWithMouseEvent(modifiers, button, as_popup)); | |
| 179 } | |
| 180 | |
| 181 TEST_F(GetNavigationPolicyTest, ControlOrMetaAndShiftLeftClickPopup) { | |
| 182 #if OS(MACOSX) | |
| 183 int modifiers = WebInputEvent::kMetaKey; | |
| 184 #else | |
| 185 int modifiers = WebInputEvent::kControlKey; | |
| 186 #endif | |
| 187 modifiers |= WebInputEvent::kShiftKey; | |
| 188 WebMouseEvent::Button button = WebMouseEvent::Button::kLeft; | |
| 189 bool as_popup = true; | |
| 190 EXPECT_EQ(kWebNavigationPolicyNewForegroundTab, | |
| 191 GetNavigationPolicyWithMouseEvent(modifiers, button, as_popup)); | |
| 192 } | |
| 193 | |
| 194 TEST_F(GetNavigationPolicyTest, MiddleClick) { | |
| 195 int modifiers = 0; | |
| 196 bool as_popup = false; | |
| 197 WebMouseEvent::Button button = WebMouseEvent::Button::kMiddle; | |
| 198 EXPECT_EQ(kWebNavigationPolicyNewBackgroundTab, | |
| 199 GetNavigationPolicyWithMouseEvent(modifiers, button, as_popup)); | |
| 200 } | |
| 201 | |
| 202 TEST_F(GetNavigationPolicyTest, MiddleClickPopup) { | |
| 203 int modifiers = 0; | |
| 204 bool as_popup = true; | |
| 205 WebMouseEvent::Button button = WebMouseEvent::Button::kMiddle; | |
| 206 EXPECT_EQ(kWebNavigationPolicyNewBackgroundTab, | |
| 207 GetNavigationPolicyWithMouseEvent(modifiers, button, as_popup)); | |
| 208 } | |
| 209 | |
| 210 TEST_F(GetNavigationPolicyTest, NoToolbarsForcesPopup) { | |
| 211 chrome_client_impl_->SetToolbarsVisible(false); | |
| 212 EXPECT_TRUE(IsNavigationPolicyPopup()); | |
| 213 chrome_client_impl_->SetToolbarsVisible(true); | |
| 214 EXPECT_FALSE(IsNavigationPolicyPopup()); | |
| 215 } | |
| 216 | |
| 217 TEST_F(GetNavigationPolicyTest, NoStatusbarIsNotPopup) { | |
| 218 chrome_client_impl_->SetStatusbarVisible(false); | |
| 219 EXPECT_FALSE(IsNavigationPolicyPopup()); | |
| 220 chrome_client_impl_->SetStatusbarVisible(true); | |
| 221 EXPECT_FALSE(IsNavigationPolicyPopup()); | |
| 222 } | |
| 223 | |
| 224 TEST_F(GetNavigationPolicyTest, NoMenubarIsNotPopup) { | |
| 225 chrome_client_impl_->SetMenubarVisible(false); | |
| 226 EXPECT_FALSE(IsNavigationPolicyPopup()); | |
| 227 chrome_client_impl_->SetMenubarVisible(true); | |
| 228 EXPECT_FALSE(IsNavigationPolicyPopup()); | |
| 229 } | |
| 230 | |
| 231 TEST_F(GetNavigationPolicyTest, NotResizableIsNotPopup) { | |
| 232 chrome_client_impl_->SetResizable(false); | |
| 233 EXPECT_FALSE(IsNavigationPolicyPopup()); | |
| 234 chrome_client_impl_->SetResizable(true); | |
| 235 EXPECT_FALSE(IsNavigationPolicyPopup()); | |
| 236 } | |
| 237 | |
| 238 class ViewCreatingClient : public FrameTestHelpers::TestWebViewClient { | 67 class ViewCreatingClient : public FrameTestHelpers::TestWebViewClient { |
| 239 public: | 68 public: |
| 240 WebView* CreateView(WebLocalFrame* opener, | 69 WebView* CreateView(WebLocalFrame* opener, |
| 241 const WebURLRequest&, | 70 const WebURLRequest&, |
| 242 const WebWindowFeatures&, | 71 const WebWindowFeatures&, |
| 243 const WebString& name, | 72 const WebString& name, |
| 244 WebNavigationPolicy, | 73 WebNavigationPolicy, |
| 245 bool) override { | 74 bool) override { |
| 246 return web_view_helper_.InitializeWithOpener(opener, true); | 75 return web_view_helper_.InitializeWithOpener(opener, true); |
| 247 } | 76 } |
| (...skipping 20 matching lines...) Expand all Loading... |
| 268 WebViewBase* web_view_; | 97 WebViewBase* web_view_; |
| 269 WebLocalFrame* main_frame_; | 98 WebLocalFrame* main_frame_; |
| 270 FrameTestHelpers::TestWebFrameClient web_frame_client_; | 99 FrameTestHelpers::TestWebFrameClient web_frame_client_; |
| 271 Persistent<ChromeClientImpl> chrome_client_impl_; | 100 Persistent<ChromeClientImpl> chrome_client_impl_; |
| 272 }; | 101 }; |
| 273 | 102 |
| 274 TEST_F(CreateWindowTest, CreateWindowFromSuspendedPage) { | 103 TEST_F(CreateWindowTest, CreateWindowFromSuspendedPage) { |
| 275 ScopedPageSuspender suspender; | 104 ScopedPageSuspender suspender; |
| 276 LocalFrame* frame = ToWebLocalFrameBase(main_frame_)->GetFrame(); | 105 LocalFrame* frame = ToWebLocalFrameBase(main_frame_)->GetFrame(); |
| 277 FrameLoadRequest request(frame->GetDocument()); | 106 FrameLoadRequest request(frame->GetDocument()); |
| 278 WindowFeatures features; | 107 WebWindowFeatures features; |
| 279 EXPECT_EQ(nullptr, | 108 EXPECT_EQ(nullptr, |
| 280 chrome_client_impl_->CreateWindow( | 109 chrome_client_impl_->CreateWindow( |
| 281 frame, request, features, kNavigationPolicyNewForegroundTab)); | 110 frame, request, features, kNavigationPolicyNewForegroundTab)); |
| 282 } | 111 } |
| 283 | 112 |
| 284 class FakeColorChooserClient | 113 class FakeColorChooserClient |
| 285 : public GarbageCollectedFinalized<FakeColorChooserClient>, | 114 : public GarbageCollectedFinalized<FakeColorChooserClient>, |
| 286 public ColorChooserClient { | 115 public ColorChooserClient { |
| 287 public: | 116 public: |
| 288 FakeColorChooserClient(Element* owner_element) | 117 FakeColorChooserClient(Element* owner_element) |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 427 Settings* settings = GetSettings(); | 256 Settings* settings = GetSettings(); |
| 428 settings->SetPagePopupsSuppressed(true); | 257 settings->SetPagePopupsSuppressed(true); |
| 429 | 258 |
| 430 EXPECT_FALSE(CanOpenPopupMenu()); | 259 EXPECT_FALSE(CanOpenPopupMenu()); |
| 431 | 260 |
| 432 settings->SetPagePopupsSuppressed(false); | 261 settings->SetPagePopupsSuppressed(false); |
| 433 EXPECT_TRUE(CanOpenPopupMenu()); | 262 EXPECT_TRUE(CanOpenPopupMenu()); |
| 434 } | 263 } |
| 435 | 264 |
| 436 } // namespace blink | 265 } // namespace blink |
| OLD | NEW |