[Metrics] Make MetricsStateManager take a callback param to check if UMA is enabled.
[chromium-blink-merge.git] / chrome / browser / ui / views / frame / browser_view_browsertest.cc
blobe573e1b2614b12dca8ce87080905df687187effd
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/ui/views/frame/browser_view.h"
7 #include "chrome/browser/ui/browser.h"
8 #include "chrome/browser/ui/browser_tabstrip.h"
9 #include "chrome/browser/ui/tabs/tab_strip_model.h"
10 #include "chrome/test/base/in_process_browser_test.h"
11 #include "content/public/browser/invalidate_type.h"
12 #include "content/public/browser/web_contents.h"
13 #include "content/public/browser/web_contents_observer.h"
15 typedef InProcessBrowserTest BrowserViewTest;
17 namespace {
19 // Used to simulate scenario in a crash. When WebContentsDestroyed() is invoked
20 // updates the navigation state of another tab.
21 class TestWebContentsObserver : public content::WebContentsObserver {
22 public:
23 TestWebContentsObserver(content::WebContents* source,
24 content::WebContents* other)
25 : content::WebContentsObserver(source),
26 other_(other) {}
27 virtual ~TestWebContentsObserver() {}
29 virtual void WebContentsDestroyed() OVERRIDE {
30 other_->NotifyNavigationStateChanged(
31 content::INVALIDATE_TYPE_URL | content::INVALIDATE_TYPE_LOAD);
34 private:
35 content::WebContents* other_;
37 DISALLOW_COPY_AND_ASSIGN(TestWebContentsObserver);
40 } // namespace
42 // Verifies don't crash when CloseNow() is invoked with two tabs in a browser.
43 // Additionally when one of the tabs is destroyed NotifyNavigationStateChanged()
44 // is invoked on the other.
45 IN_PROC_BROWSER_TEST_F(BrowserViewTest, CloseWithTabs) {
46 Browser* browser2 =
47 new Browser(Browser::CreateParams(browser()->profile(),
48 browser()->host_desktop_type()));
49 chrome::AddTabAt(browser2, GURL(), -1, true);
50 chrome::AddTabAt(browser2, GURL(), -1, true);
51 TestWebContentsObserver observer(
52 browser2->tab_strip_model()->GetWebContentsAt(0),
53 browser2->tab_strip_model()->GetWebContentsAt(1));
54 BrowserView::GetBrowserViewForBrowser(browser2)->GetWidget()->CloseNow();
57 // Same as CloseWithTabs, but activates the first tab, which is the first tab
58 // BrowserView will destroy.
59 IN_PROC_BROWSER_TEST_F(BrowserViewTest, CloseWithTabsStartWithActive) {
60 Browser* browser2 =
61 new Browser(Browser::CreateParams(browser()->profile(),
62 browser()->host_desktop_type()));
63 chrome::AddTabAt(browser2, GURL(), -1, true);
64 chrome::AddTabAt(browser2, GURL(), -1, true);
65 browser2->tab_strip_model()->ActivateTabAt(0, true);
66 TestWebContentsObserver observer(
67 browser2->tab_strip_model()->GetWebContentsAt(0),
68 browser2->tab_strip_model()->GetWebContentsAt(1));
69 BrowserView::GetBrowserViewForBrowser(browser2)->GetWidget()->CloseNow();