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
;
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
{
23 TestWebContentsObserver(content::WebContents
* source
,
24 content::WebContents
* other
)
25 : content::WebContentsObserver(source
),
27 virtual ~TestWebContentsObserver() {}
29 virtual void WebContentsDestroyed(
30 content::WebContents
* web_contents
) OVERRIDE
{
31 other_
->NotifyNavigationStateChanged(
32 content::INVALIDATE_TYPE_URL
| content::INVALIDATE_TYPE_LOAD
);
36 content::WebContents
* other_
;
38 DISALLOW_COPY_AND_ASSIGN(TestWebContentsObserver
);
43 // Verifies don't crash when CloseNow() is invoked with two tabs in a browser.
44 // Additionally when one of the tabs is destroyed NotifyNavigationStateChanged()
45 // is invoked on the other.
46 IN_PROC_BROWSER_TEST_F(BrowserViewTest
, CloseWithTabs
) {
48 new Browser(Browser::CreateParams(browser()->profile(),
49 browser()->host_desktop_type()));
50 chrome::AddTabAt(browser2
, GURL(), -1, true);
51 chrome::AddTabAt(browser2
, GURL(), -1, true);
52 TestWebContentsObserver
observer(
53 browser2
->tab_strip_model()->GetWebContentsAt(0),
54 browser2
->tab_strip_model()->GetWebContentsAt(1));
55 BrowserView::GetBrowserViewForBrowser(browser2
)->GetWidget()->CloseNow();