Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(489)

Side by Side Diff: chrome/browser/ui/views/extensions/extension_message_bubble_view.cc

Issue 1768623002: [Extension UI Views] Add tests for clicking the different message bubble buttons (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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/extensions/extension_message_bubble_view.h" 5 #include "chrome/browser/ui/views/extensions/extension_message_bubble_view.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/location.h" 9 #include "base/location.h"
10 #include "base/single_thread_task_runner.h" 10 #include "base/single_thread_task_runner.h"
(...skipping 22 matching lines...) Expand all
33 const int kHeadlineRowPadding = 10; 33 const int kHeadlineRowPadding = 10;
34 const int kMessageBubblePadding = 11; 34 const int kMessageBubblePadding = 11;
35 35
36 // How long to wait until showing the bubble (in seconds). 36 // How long to wait until showing the bubble (in seconds).
37 int g_bubble_appearance_wait_time = 5; 37 int g_bubble_appearance_wait_time = 5;
38 38
39 } // namespace 39 } // namespace
40 40
41 namespace extensions { 41 namespace extensions {
42 42
43 ExtensionMessageBubbleView*
44 ExtensionMessageBubbleView::active_bubble_for_testing_ = nullptr;
45
43 ExtensionMessageBubbleView::ExtensionMessageBubbleView( 46 ExtensionMessageBubbleView::ExtensionMessageBubbleView(
44 views::View* anchor_view, 47 views::View* anchor_view,
45 views::BubbleBorder::Arrow arrow_location, 48 views::BubbleBorder::Arrow arrow_location,
46 scoped_ptr<extensions::ExtensionMessageBubbleController> controller) 49 scoped_ptr<extensions::ExtensionMessageBubbleController> controller)
47 : BubbleDelegateView(anchor_view, arrow_location), 50 : BubbleDelegateView(anchor_view, arrow_location),
48 controller_(std::move(controller)), 51 controller_(std::move(controller)),
49 anchor_view_(anchor_view), 52 anchor_view_(anchor_view),
50 headline_(NULL), 53 headline_(NULL),
51 learn_more_(NULL), 54 learn_more_(NULL),
52 dismiss_button_(NULL), 55 dismiss_button_(NULL),
(...skipping 17 matching lines...) Expand all
70 // bubbles into the focus cycle). Another benefit of delaying the show is 73 // bubbles into the focus cycle). Another benefit of delaying the show is
71 // that fade-in works (the fade-in isn't apparent if the the bubble appears at 74 // that fade-in works (the fade-in isn't apparent if the the bubble appears at
72 // startup). 75 // startup).
73 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( 76 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
74 FROM_HERE, base::Bind(&ExtensionMessageBubbleView::ShowBubble, 77 FROM_HERE, base::Bind(&ExtensionMessageBubbleView::ShowBubble,
75 weak_factory_.GetWeakPtr()), 78 weak_factory_.GetWeakPtr()),
76 base::TimeDelta::FromSeconds(g_bubble_appearance_wait_time)); 79 base::TimeDelta::FromSeconds(g_bubble_appearance_wait_time));
77 } 80 }
78 81
79 void ExtensionMessageBubbleView::OnWidgetDestroying(views::Widget* widget) { 82 void ExtensionMessageBubbleView::OnWidgetDestroying(views::Widget* widget) {
83 if (active_bubble_for_testing_ == this)
84 active_bubble_for_testing_ = nullptr;
80 // To catch Esc, we monitor destroy message. Unless the link has been clicked, 85 // To catch Esc, we monitor destroy message. Unless the link has been clicked,
81 // we assume Dismiss was the action taken. 86 // we assume Dismiss was the action taken.
82 if (!link_clicked_ && !action_taken_) { 87 if (!link_clicked_ && !action_taken_) {
83 bool closed_on_deactivation = close_reason() == CloseReason::DEACTIVATION; 88 bool closed_on_deactivation = close_reason() == CloseReason::DEACTIVATION;
84 controller_->OnBubbleDismiss(closed_on_deactivation); 89 controller_->OnBubbleDismiss(closed_on_deactivation);
85 } 90 }
86 } 91 }
87 92
88 void ExtensionMessageBubbleView::set_bubble_appearance_wait_time_for_testing( 93 void ExtensionMessageBubbleView::set_bubble_appearance_wait_time_for_testing(
89 int time_in_seconds) { 94 int time_in_seconds) {
90 g_bubble_appearance_wait_time = time_in_seconds; 95 g_bubble_appearance_wait_time = time_in_seconds;
91 } 96 }
92 97
93 //////////////////////////////////////////////////////////////////////////////// 98 ////////////////////////////////////////////////////////////////////////////////
94 // ExtensionMessageBubbleView - private. 99 // ExtensionMessageBubbleView - private.
95 100
96 ExtensionMessageBubbleView::~ExtensionMessageBubbleView() {} 101 ExtensionMessageBubbleView::~ExtensionMessageBubbleView() {}
97 102
98 void ExtensionMessageBubbleView::ShowBubble() { 103 void ExtensionMessageBubbleView::ShowBubble() {
104 active_bubble_for_testing_ = this;
99 // Since we delay in showing the bubble, the applicable extension(s) may 105 // Since we delay in showing the bubble, the applicable extension(s) may
100 // have been removed. 106 // have been removed.
101 if (controller_->ShouldShow()) { 107 if (controller_->ShouldShow()) {
102 controller_->OnShown(); 108 controller_->OnShown();
103 GetWidget()->Show(); 109 GetWidget()->Show();
104 } else { 110 } else {
105 GetWidget()->Close(); 111 GetWidget()->Close();
106 } 112 }
107 } 113 }
108 114
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 state->role = ui::AX_ROLE_ALERT; 232 state->role = ui::AX_ROLE_ALERT;
227 } 233 }
228 234
229 void ExtensionMessageBubbleView::ViewHierarchyChanged( 235 void ExtensionMessageBubbleView::ViewHierarchyChanged(
230 const ViewHierarchyChangedDetails& details) { 236 const ViewHierarchyChangedDetails& details) {
231 if (details.is_add && details.child == this) 237 if (details.is_add && details.child == this)
232 NotifyAccessibilityEvent(ui::AX_EVENT_ALERT, true); 238 NotifyAccessibilityEvent(ui::AX_EVENT_ALERT, true);
233 } 239 }
234 240
235 } // namespace extensions 241 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698