Chromium Code Reviews| Index: chrome/browser/metrics/desktop_engagement/chrome_visibility_observer_browsertest.cc |
| diff --git a/chrome/browser/metrics/desktop_engagement/chrome_visibility_observer_browsertest.cc b/chrome/browser/metrics/desktop_engagement/chrome_visibility_observer_browsertest.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..52cb554d58fe64b09199ed3b8956599afbfe48c2 |
| --- /dev/null |
| +++ b/chrome/browser/metrics/desktop_engagement/chrome_visibility_observer_browsertest.cc |
| @@ -0,0 +1,49 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "chrome/browser/metrics/desktop_engagement/chrome_visibility_observer.h" |
| + |
| +#include "base/memory/singleton.h" |
| +#include "chrome/browser/chrome_notification_types.h" |
| +#include "chrome/browser/ui/browser.h" |
| +#include "chrome/browser/ui/browser_list.h" |
| +#include "chrome/test/base/in_process_browser_test.h" |
| +#include "chrome/test/base/ui_test_utils.h" |
| +#include "content/public/browser/notification_service.h" |
| +#include "content/public/test/test_utils.h" |
| + |
| +// Mock class for |ChromeVisibilityObserver| for testing. |
| +class MockChromeVisibilityObserver : public metrics::ChromeVisibilityObserver { |
| + public: |
| + MockChromeVisibilityObserver() : is_active_(false) {} |
| + |
| + bool IsActive() const { return is_active_; } |
|
Alexei Svitkine (slow)
2016/07/28 18:37:22
is_active()
gayane -on leave until 09-2017
2016/07/28 21:21:34
Done.
|
| + |
| + private: |
| + void SendVisibilityChangeEvent(bool active) override { is_active_ = active; } |
| + |
| + bool is_active_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(MockChromeVisibilityObserver); |
| +}; |
| + |
| +class ChromeVisibilityObserverBrowserTest : public InProcessBrowserTest {}; |
| + |
| +IN_PROC_BROWSER_TEST_F(ChromeVisibilityObserverBrowserTest, VisibilityTest) { |
| + MockChromeVisibilityObserver observer; |
| + |
| + EXPECT_FALSE(observer.IsActive()); |
| + Browser* new_browser = CreateBrowser(browser()->profile()); |
| + EXPECT_TRUE(observer.IsActive()); |
| + |
| + Browser* incognito_browser = CreateIncognitoBrowser(); |
| + EXPECT_TRUE(observer.IsActive()); |
| + |
| + CloseBrowserSynchronously(incognito_browser); |
| + EXPECT_TRUE(observer.IsActive()); |
| + |
| + CloseBrowserSynchronously(new_browser); |
| + CloseBrowserSynchronously(browser()); |
| + EXPECT_FALSE(observer.IsActive()); |
| +} |