| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/ui/views/first_run_bubble.h" |
| 5 #include "base/macros.h" | 6 #include "base/macros.h" |
| 6 #include "chrome/browser/search_engines/template_url_service_factory.h" | 7 #include "chrome/browser/search_engines/template_url_service_factory.h" |
| 7 #include "chrome/browser/ui/views/first_run_bubble.h" | |
| 8 #include "chrome/test/base/testing_profile.h" | 8 #include "chrome/test/base/testing_profile.h" |
| 9 #include "components/search_engines/template_url.h" | 9 #include "components/search_engines/template_url.h" |
| 10 #include "components/search_engines/template_url_service.h" | 10 #include "components/search_engines/template_url_service.h" |
| 11 #include "content/public/test/test_browser_thread.h" | 11 #include "content/public/test/test_browser_thread.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
| 13 #include "ui/aura/window.h" | 13 #include "ui/aura/window.h" |
| 14 #include "ui/aura/window_tree_host.h" | 14 #include "ui/aura/window_tree_host.h" |
| 15 #include "ui/events/event.h" | 15 #include "ui/events/event.h" |
| 16 #include "ui/events/event_processor.h" | 16 #include "ui/events/event_sink.h" |
| 17 #include "ui/events/event_utils.h" | 17 #include "ui/events/event_utils.h" |
| 18 #include "ui/views/test/views_test_base.h" | 18 #include "ui/views/test/views_test_base.h" |
| 19 #include "ui/views/view.h" | 19 #include "ui/views/view.h" |
| 20 #include "ui/views/widget/widget.h" | 20 #include "ui/views/widget/widget.h" |
| 21 | 21 |
| 22 // Provides functionality to observe the widget passed in the constructor for | 22 // Provides functionality to observe the widget passed in the constructor for |
| 23 // the widget closing event. | 23 // the widget closing event. |
| 24 class WidgetClosingObserver : public views::WidgetObserver { | 24 class WidgetClosingObserver : public views::WidgetObserver { |
| 25 public: | 25 public: |
| 26 explicit WidgetClosingObserver(views::Widget* widget) | 26 explicit WidgetClosingObserver(views::Widget* widget) |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 | 101 |
| 102 FirstRunBubble* delegate = | 102 FirstRunBubble* delegate = |
| 103 FirstRunBubble::ShowBubble(NULL, anchor_widget->GetContentsView()); | 103 FirstRunBubble::ShowBubble(NULL, anchor_widget->GetContentsView()); |
| 104 EXPECT_TRUE(delegate != NULL); | 104 EXPECT_TRUE(delegate != NULL); |
| 105 | 105 |
| 106 anchor_widget->GetContentsView()->RequestFocus(); | 106 anchor_widget->GetContentsView()->RequestFocus(); |
| 107 | 107 |
| 108 std::unique_ptr<WidgetClosingObserver> widget_observer( | 108 std::unique_ptr<WidgetClosingObserver> widget_observer( |
| 109 new WidgetClosingObserver(delegate->GetWidget())); | 109 new WidgetClosingObserver(delegate->GetWidget())); |
| 110 | 110 |
| 111 ui::EventDispatchDetails details = | 111 ui::EventDispatchDetails details = anchor_widget->GetNativeWindow() |
| 112 anchor_widget->GetNativeWindow()->GetHost()->event_processor()-> | 112 ->GetHost() |
| 113 OnEventFromSource(event); | 113 ->event_sink() |
| 114 ->OnEventFromSource(event); |
| 114 EXPECT_FALSE(details.dispatcher_destroyed); | 115 EXPECT_FALSE(details.dispatcher_destroyed); |
| 115 | 116 |
| 116 EXPECT_TRUE(widget_observer->widget_destroyed()); | 117 EXPECT_TRUE(widget_observer->widget_destroyed()); |
| 117 } | 118 } |
| 118 | 119 |
| 119 TEST_F(FirstRunBubbleTest, CreateAndClose) { | 120 TEST_F(FirstRunBubbleTest, CreateAndClose) { |
| 120 // Create the anchor and parent widgets. | 121 // Create the anchor and parent widgets. |
| 121 views::Widget::InitParams params = | 122 views::Widget::InitParams params = |
| 122 CreateParams(views::Widget::InitParams::TYPE_WINDOW); | 123 CreateParams(views::Widget::InitParams::TYPE_WINDOW); |
| 123 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 124 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 146 CreateAndCloseBubbleOnEventTest(&mouse_down); | 147 CreateAndCloseBubbleOnEventTest(&mouse_down); |
| 147 } | 148 } |
| 148 | 149 |
| 149 TEST_F(FirstRunBubbleTest, CloseBubbleOnTouchDownEvent) { | 150 TEST_F(FirstRunBubbleTest, CloseBubbleOnTouchDownEvent) { |
| 150 ui::TouchEvent touch_down( | 151 ui::TouchEvent touch_down( |
| 151 ui::ET_TOUCH_PRESSED, gfx::Point(10, 10), ui::EventTimeForNow(), | 152 ui::ET_TOUCH_PRESSED, gfx::Point(10, 10), ui::EventTimeForNow(), |
| 152 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_TOUCH, 0)); | 153 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_TOUCH, 0)); |
| 153 CreateAndCloseBubbleOnEventTest(&touch_down); | 154 CreateAndCloseBubbleOnEventTest(&touch_down); |
| 154 } | 155 } |
| 155 | 156 |
| OLD | NEW |