OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright (C) 2012 Google Inc. All rights reserved. |
| 3 * |
| 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are |
| 6 * met: |
| 7 * |
| 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above |
| 11 * copyright notice, this list of conditions and the following disclaimer |
| 12 * in the documentation and/or other materials provided with the |
| 13 * distribution. |
| 14 * * Neither the name of Google Inc. nor the names of its |
| 15 * contributors may be used to endorse or promote products derived from |
| 16 * this software without specific prior written permission. |
| 17 * |
| 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ |
| 30 |
| 31 #include "core/page/CreateWindow.h" |
| 32 #include "public/platform/WebInputEvent.h" |
| 33 #include "public/platform/WebMouseEvent.h" |
| 34 #include "testing/gtest/include/gtest/gtest.h" |
| 35 |
| 36 namespace blink { |
| 37 |
| 38 class EffectiveNavigationPolicyTest : public testing::Test { |
| 39 protected: |
| 40 NavigationPolicy GetNavigationPolicyWithMouseEvent( |
| 41 int modifiers, |
| 42 WebMouseEvent::Button button, |
| 43 bool as_popup) { |
| 44 WebMouseEvent event(WebInputEvent::kMouseUp, modifiers, |
| 45 WebInputEvent::kTimeStampForTesting); |
| 46 event.button = button; |
| 47 return EffectiveNavigationPolicy(kNavigationPolicyIgnore, &event, |
| 48 !as_popup); |
| 49 } |
| 50 }; |
| 51 |
| 52 TEST_F(EffectiveNavigationPolicyTest, LeftClick) { |
| 53 int modifiers = 0; |
| 54 WebMouseEvent::Button button = WebMouseEvent::Button::kLeft; |
| 55 bool as_popup = false; |
| 56 EXPECT_EQ(kNavigationPolicyNewForegroundTab, |
| 57 GetNavigationPolicyWithMouseEvent(modifiers, button, as_popup)); |
| 58 } |
| 59 |
| 60 TEST_F(EffectiveNavigationPolicyTest, LeftClickPopup) { |
| 61 int modifiers = 0; |
| 62 WebMouseEvent::Button button = WebMouseEvent::Button::kLeft; |
| 63 bool as_popup = true; |
| 64 EXPECT_EQ(kNavigationPolicyNewPopup, |
| 65 GetNavigationPolicyWithMouseEvent(modifiers, button, as_popup)); |
| 66 } |
| 67 |
| 68 TEST_F(EffectiveNavigationPolicyTest, ShiftLeftClick) { |
| 69 int modifiers = WebInputEvent::kShiftKey; |
| 70 WebMouseEvent::Button button = WebMouseEvent::Button::kLeft; |
| 71 bool as_popup = false; |
| 72 EXPECT_EQ(kNavigationPolicyNewWindow, |
| 73 GetNavigationPolicyWithMouseEvent(modifiers, button, as_popup)); |
| 74 } |
| 75 |
| 76 TEST_F(EffectiveNavigationPolicyTest, ShiftLeftClickPopup) { |
| 77 int modifiers = WebInputEvent::kShiftKey; |
| 78 WebMouseEvent::Button button = WebMouseEvent::Button::kLeft; |
| 79 bool as_popup = true; |
| 80 EXPECT_EQ(kNavigationPolicyNewPopup, |
| 81 GetNavigationPolicyWithMouseEvent(modifiers, button, as_popup)); |
| 82 } |
| 83 |
| 84 TEST_F(EffectiveNavigationPolicyTest, ControlOrMetaLeftClick) { |
| 85 #if OS(MACOSX) |
| 86 int modifiers = WebInputEvent::kMetaKey; |
| 87 #else |
| 88 int modifiers = WebInputEvent::kControlKey; |
| 89 #endif |
| 90 WebMouseEvent::Button button = WebMouseEvent::Button::kLeft; |
| 91 bool as_popup = false; |
| 92 EXPECT_EQ(kNavigationPolicyNewBackgroundTab, |
| 93 GetNavigationPolicyWithMouseEvent(modifiers, button, as_popup)); |
| 94 } |
| 95 |
| 96 TEST_F(EffectiveNavigationPolicyTest, ControlOrMetaLeftClickPopup) { |
| 97 #if OS(MACOSX) |
| 98 int modifiers = WebInputEvent::kMetaKey; |
| 99 #else |
| 100 int modifiers = WebInputEvent::kControlKey; |
| 101 #endif |
| 102 WebMouseEvent::Button button = WebMouseEvent::Button::kLeft; |
| 103 bool as_popup = true; |
| 104 EXPECT_EQ(kNavigationPolicyNewBackgroundTab, |
| 105 GetNavigationPolicyWithMouseEvent(modifiers, button, as_popup)); |
| 106 } |
| 107 |
| 108 TEST_F(EffectiveNavigationPolicyTest, ControlOrMetaAndShiftLeftClick) { |
| 109 #if OS(MACOSX) |
| 110 int modifiers = WebInputEvent::kMetaKey; |
| 111 #else |
| 112 int modifiers = WebInputEvent::kControlKey; |
| 113 #endif |
| 114 modifiers |= WebInputEvent::kShiftKey; |
| 115 WebMouseEvent::Button button = WebMouseEvent::Button::kLeft; |
| 116 bool as_popup = false; |
| 117 EXPECT_EQ(kNavigationPolicyNewForegroundTab, |
| 118 GetNavigationPolicyWithMouseEvent(modifiers, button, as_popup)); |
| 119 } |
| 120 |
| 121 TEST_F(EffectiveNavigationPolicyTest, ControlOrMetaAndShiftLeftClickPopup) { |
| 122 #if OS(MACOSX) |
| 123 int modifiers = WebInputEvent::kMetaKey; |
| 124 #else |
| 125 int modifiers = WebInputEvent::kControlKey; |
| 126 #endif |
| 127 modifiers |= WebInputEvent::kShiftKey; |
| 128 WebMouseEvent::Button button = WebMouseEvent::Button::kLeft; |
| 129 bool as_popup = true; |
| 130 EXPECT_EQ(kNavigationPolicyNewForegroundTab, |
| 131 GetNavigationPolicyWithMouseEvent(modifiers, button, as_popup)); |
| 132 } |
| 133 |
| 134 TEST_F(EffectiveNavigationPolicyTest, MiddleClick) { |
| 135 int modifiers = 0; |
| 136 bool as_popup = false; |
| 137 WebMouseEvent::Button button = WebMouseEvent::Button::kMiddle; |
| 138 EXPECT_EQ(kNavigationPolicyNewBackgroundTab, |
| 139 GetNavigationPolicyWithMouseEvent(modifiers, button, as_popup)); |
| 140 } |
| 141 |
| 142 TEST_F(EffectiveNavigationPolicyTest, MiddleClickPopup) { |
| 143 int modifiers = 0; |
| 144 bool as_popup = true; |
| 145 WebMouseEvent::Button button = WebMouseEvent::Button::kMiddle; |
| 146 EXPECT_EQ(kNavigationPolicyNewBackgroundTab, |
| 147 GetNavigationPolicyWithMouseEvent(modifiers, button, as_popup)); |
| 148 } |
| 149 |
| 150 TEST_F(EffectiveNavigationPolicyTest, NoToolbarsForcesPopup) { |
| 151 EXPECT_EQ(kNavigationPolicyNewPopup, |
| 152 EffectiveNavigationPolicy(kNavigationPolicyIgnore, nullptr, false)); |
| 153 EXPECT_EQ(kNavigationPolicyNewForegroundTab, |
| 154 EffectiveNavigationPolicy(kNavigationPolicyIgnore, nullptr, true)); |
| 155 } |
| 156 |
| 157 } // namespace blink |
OLD | NEW |