diff options
author | oshima@google.com <oshima@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-10-19 22:57:38 +0000 |
---|---|---|
committer | oshima@google.com <oshima@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-10-19 22:57:38 +0000 |
commit | 75c920505ddfb2d49c194c76bde64edd6b3f91f2 (patch) | |
tree | c91c7f5859b5b06865fb17fb998a10099f7ccd52 | |
parent | 18a4df8cd3d30a3ce08bffb514c81af288b92f8e (diff) | |
download | chromium_src-75c920505ddfb2d49c194c76bde64edd6b3f91f2.zip chromium_src-75c920505ddfb2d49c194c76bde64edd6b3f91f2.tar.gz chromium_src-75c920505ddfb2d49c194c76bde64edd6b3f91f2.tar.bz2 |
Fix visible parameter passed to WnidowObserver
BUG=none
TEST=added test to window_unittests.cc
R=sky@chromium.org
Review URL: http://codereview.chromium.org/8344052
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@106402 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | ui/aura/window.cc | 2 | ||||
-rw-r--r-- | ui/aura/window_observer.h | 2 | ||||
-rw-r--r-- | ui/aura/window_unittest.cc | 63 |
3 files changed, 65 insertions, 2 deletions
diff --git a/ui/aura/window.cc b/ui/aura/window.cc index ad812bb..3d74cb6 100644 --- a/ui/aura/window.cc +++ b/ui/aura/window.cc @@ -420,7 +420,7 @@ void Window::SetVisible(bool visible) { delegate_->OnWindowVisibilityChanged(is_visible); } FOR_EACH_OBSERVER(WindowObserver, observers_, - OnWindowVisibilityChanged(this, is_visible)); + OnWindowVisibilityChanged(this, visible)); } void Window::SchedulePaint() { diff --git a/ui/aura/window_observer.h b/ui/aura/window_observer.h index 224f0d0..f3ecabc 100644 --- a/ui/aura/window_observer.h +++ b/ui/aura/window_observer.h @@ -23,7 +23,7 @@ class AURA_EXPORT WindowObserver { // Invoked when the SetVisible() is invoked on a window. |visible| is the // value supplied to SetVisible(). If |visible| is true, window->IsVisible() // may still return false. See description in Window::IsVisible() for details. - virtual void OnWindowVisibilityChanged(Window* window, bool visibile) {} + virtual void OnWindowVisibilityChanged(Window* window, bool visible) {} protected: virtual ~WindowObserver() {} diff --git a/ui/aura/window_unittest.cc b/ui/aura/window_unittest.cc index 79504d8..a73d85e 100644 --- a/ui/aura/window_unittest.cc +++ b/ui/aura/window_unittest.cc @@ -983,10 +983,23 @@ TEST_F(ToplevelWindowTest, TopMostActivate) { class WindowObserverTest : public WindowTest, public WindowObserver { public: + struct VisibilityInfo { + bool window_visible; + bool visible_param; + }; + WindowObserverTest() : added_count_(0), removed_count_(0) {} virtual ~WindowObserverTest() {} + const VisibilityInfo* GetVisibilityInfo() const { + return visibility_info_.get(); + } + + void ResetVisibilityInfo() { + visibility_info_.reset(); + } + // Returns a description of the WindowObserver methods that have been invoked. std::string WindowObserverCountStateAndClear() { std::string result( @@ -1005,8 +1018,16 @@ class WindowObserverTest : public WindowTest, removed_count_++; } + virtual void OnWindowVisibilityChanged(Window* window, + bool visible) OVERRIDE { + visibility_info_.reset(new VisibilityInfo); + visibility_info_->window_visible = window->IsVisible(); + visibility_info_->visible_param = visible; + } + int added_count_; int removed_count_; + scoped_ptr<VisibilityInfo> visibility_info_; DISALLOW_COPY_AND_ASSIGN(WindowObserverTest); }; @@ -1035,6 +1056,48 @@ TEST_F(WindowObserverTest, WindowObserver) { w1->RemoveObserver(this); } +// Test if OnWindowVisibilityChagned is invoked with expected +// parameters. +TEST_F(WindowObserverTest, WindowVisibility) { + scoped_ptr<Window> w1(CreateTestWindowWithId(1, NULL)); + scoped_ptr<Window> w2(CreateTestWindowWithId(1, w1.get())); + w2->AddObserver(this); + + // Hide should make the window invisible and the passed visible + // parameter is false. + w2->Hide(); + EXPECT_FALSE(!GetVisibilityInfo()); + EXPECT_FALSE(!GetVisibilityInfo()); + if (!GetVisibilityInfo()) + return; + EXPECT_FALSE(GetVisibilityInfo()->window_visible); + EXPECT_FALSE(GetVisibilityInfo()->visible_param); + + // If parent isn't visible, showing window won't make the window visible, but + // passed visible value must be true. + w1->Hide(); + ResetVisibilityInfo(); + EXPECT_TRUE(!GetVisibilityInfo()); + w2->Show(); + EXPECT_FALSE(!GetVisibilityInfo()); + if (!GetVisibilityInfo()) + return; + EXPECT_FALSE(GetVisibilityInfo()->window_visible); + EXPECT_TRUE(GetVisibilityInfo()->visible_param); + + // If parent is visible, showing window will make the window + // visible and the passed visible value is true. + w1->Show(); + w2->Hide(); + ResetVisibilityInfo(); + w2->Show(); + EXPECT_FALSE(!GetVisibilityInfo()); + if (!GetVisibilityInfo()) + return; + EXPECT_TRUE(GetVisibilityInfo()->window_visible); + EXPECT_TRUE(GetVisibilityInfo()->visible_param); +} + class DesktopObserverTest : public WindowTest, public DesktopObserver { public: |