- add sources.
[platform/framework/web/crosswalk.git] / src / chrome / browser / ui / views / frame / browser_view_browsertest.cc
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.
4
5 #include "chrome/browser/ui/views/frame/browser_view.h"
6
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"
14
15 typedef InProcessBrowserTest BrowserViewTest;
16
17 namespace {
18
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() {}
28
29   virtual void WebContentsDestroyed(
30       content::WebContents* web_contents) OVERRIDE {
31     other_->NotifyNavigationStateChanged(
32         content::INVALIDATE_TYPE_URL | content::INVALIDATE_TYPE_LOAD);
33   }
34
35  private:
36   content::WebContents* other_;
37
38   DISALLOW_COPY_AND_ASSIGN(TestWebContentsObserver);
39 };
40
41 }  // namespace
42
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) {
47   Browser* browser2 =
48       new Browser(Browser::CreateParams(browser()->profile(),
49                                         browser()->host_desktop_type()));
50   chrome::AddBlankTabAt(browser2, -1, true);
51   chrome::AddBlankTabAt(browser2, -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();
56 }