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

Side by Side Diff: ui/views/widget/widget_unittest.cc

Issue 10383234: views: Do not set capture on a widget if it cannot be activated. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: self-nit Created 8 years, 7 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 | Annotate | Revision Log
« no previous file with comments | « ui/views/widget/widget.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "base/basictypes.h" 5 #include "base/basictypes.h"
6 #include "base/memory/scoped_ptr.h" 6 #include "base/memory/scoped_ptr.h"
7 #include "base/message_loop.h" 7 #include "base/message_loop.h"
8 #include "testing/gtest/include/gtest/gtest.h" 8 #include "testing/gtest/include/gtest/gtest.h"
9 #include "ui/gfx/native_widget_types.h" 9 #include "ui/gfx/native_widget_types.h"
10 #include "ui/gfx/point.h" 10 #include "ui/gfx/point.h"
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 return mouse_capture_; 53 return mouse_capture_;
54 } 54 }
55 55
56 private: 56 private:
57 bool mouse_capture_; 57 bool mouse_capture_;
58 58
59 DISALLOW_COPY_AND_ASSIGN(NativeWidgetCapture); 59 DISALLOW_COPY_AND_ASSIGN(NativeWidgetCapture);
60 }; 60 };
61 #endif 61 #endif
62 62
63 class NonActivatableDelegate : public WidgetDelegateView {
64 public:
65 NonActivatableDelegate() {}
66 virtual ~NonActivatableDelegate() {}
67
68 // Overridden from WidgetDelegate.
69 virtual bool CanActivate() const OVERRIDE {
70 return false;
71 }
72
73 private:
74 DISALLOW_COPY_AND_ASSIGN(NonActivatableDelegate);
75 };
76
63 // A typedef that inserts our mock-capture NativeWidget implementation for 77 // A typedef that inserts our mock-capture NativeWidget implementation for
64 // relevant platforms. 78 // relevant platforms.
65 #if defined(USE_AURA) 79 #if defined(USE_AURA)
66 typedef NativeWidgetCapture NativeWidgetPlatformForTest; 80 typedef NativeWidgetCapture NativeWidgetPlatformForTest;
67 #elif defined(OS_WIN) 81 #elif defined(OS_WIN)
68 typedef NativeWidgetWin NativeWidgetPlatformForTest; 82 typedef NativeWidgetWin NativeWidgetPlatformForTest;
69 #endif 83 #endif
70 84
71 // A view that always processes all mouse events. 85 // A view that always processes all mouse events.
72 class MouseView : public View { 86 class MouseView : public View {
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after
316 330
317 child_popup->Show(); 331 child_popup->Show();
318 332
319 EXPECT_TRUE(child_popup->IsVisible()); 333 EXPECT_TRUE(child_popup->IsVisible());
320 334
321 toplevel->CloseNow(); 335 toplevel->CloseNow();
322 // |child_popup| should be automatically destroyed with |toplevel|. 336 // |child_popup| should be automatically destroyed with |toplevel|.
323 } 337 }
324 #endif 338 #endif
325 339
340 TEST_F(WidgetTest, ActivationCapture) {
341 Widget* first = CreateTopLevelPlatformWidget();
342 first->Show();
343 first->SetMouseCapture(NULL);
344 RunPendingMessages();
345 EXPECT_TRUE(WidgetHasMouseCapture(first));
346
347 Widget* second = new Widget;
348 Widget::InitParams params(Widget::InitParams::TYPE_BUBBLE);
349 params.transparent = true;
350 params.close_on_deactivate = true;
351 params.delegate = new NonActivatableDelegate;
352 second->Init(params);
353 second->Show();
354 RunPendingMessages();
355 EXPECT_FALSE(WidgetHasMouseCapture(second));
356
357 second->CloseNow();
358 first->CloseNow();
359 }
360
326 //////////////////////////////////////////////////////////////////////////////// 361 ////////////////////////////////////////////////////////////////////////////////
327 // Widget ownership tests. 362 // Widget ownership tests.
328 // 363 //
329 // Tests various permutations of Widget ownership specified in the 364 // Tests various permutations of Widget ownership specified in the
330 // InitParams::Ownership param. 365 // InitParams::Ownership param.
331 366
332 // A WidgetTest that supplies a toplevel widget for NativeWidget to parent to. 367 // A WidgetTest that supplies a toplevel widget for NativeWidget to parent to.
333 class WidgetOwnershipTest : public WidgetTest { 368 class WidgetOwnershipTest : public WidgetTest {
334 public: 369 public:
335 WidgetOwnershipTest() {} 370 WidgetOwnershipTest() {}
(...skipping 479 matching lines...) Expand 10 before | Expand all | Expand 10 after
815 // And it stays maximized after getting out of full screen. 850 // And it stays maximized after getting out of full screen.
816 EXPECT_EQ(ui::SHOW_STATE_MAXIMIZED, GetWidgetShowState(toplevel)); 851 EXPECT_EQ(ui::SHOW_STATE_MAXIMIZED, GetWidgetShowState(toplevel));
817 852
818 // Clean up. 853 // Clean up.
819 toplevel->Close(); 854 toplevel->Close();
820 RunPendingMessages(); 855 RunPendingMessages();
821 } 856 }
822 857
823 } // namespace 858 } // namespace
824 } // namespace views 859 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/widget/widget.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698