1 // Copyright (c) 2011 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 <string>
6
7 #include "base/message_loop.h"
8 #include "base/process_util.h"
9 #include "chrome/browser/renderer_host/web_cache_manager.h"
10 #include "chrome/browser/ui/browser.h"
11 #include "chrome/test/in_process_browser_test.h"
12 #include "chrome/test/ui_test_utils.h"
13 #include "content/browser/renderer_host/render_process_host.h"
14 #include "content/browser/tab_contents/tab_contents.h"
15 #include "content/common/result_codes.h"
16 #include "testing/gtest/include/gtest/gtest.h"
17
18 class WebCacheManagerBrowserTest : public InProcessBrowserTest {
19 };
20
21 // Regression test for http://crbug.com/12362. If a renderer crashes and the
22 // user navigates to another tab and back, the browser doesn't crash.
23 // Flaky, http://crbug.com/15288. Disabled, http://crbug.com/69918.
IN_PROC_BROWSER_TEST_F(WebCacheManagerBrowserTest,DISABLED_CrashOnceOnly)24 IN_PROC_BROWSER_TEST_F(WebCacheManagerBrowserTest, DISABLED_CrashOnceOnly) {
25 const FilePath kTestDir(FILE_PATH_LITERAL("google"));
26 const FilePath kTestFile(FILE_PATH_LITERAL("google.html"));
27 GURL url(ui_test_utils::GetTestUrl(kTestDir, kTestFile));
28
29 ui_test_utils::NavigateToURL(browser(), url);
30
31 browser()->NewTab();
32 ui_test_utils::NavigateToURL(browser(), url);
33
34 TabContents* tab = browser()->GetTabContentsAt(0);
35 ASSERT_TRUE(tab != NULL);
36 base::KillProcess(tab->GetRenderProcessHost()->GetHandle(),
37 ResultCodes::KILLED, true);
38
39 browser()->ActivateTabAt(0, true);
40 browser()->NewTab();
41 ui_test_utils::NavigateToURL(browser(), url);
42
43 browser()->ActivateTabAt(0, true);
44 browser()->NewTab();
45 ui_test_utils::NavigateToURL(browser(), url);
46
47 // We would have crashed at the above line with the bug.
48
49 browser()->ActivateTabAt(0, true);
50 browser()->CloseTab();
51 browser()->ActivateTabAt(0, true);
52 browser()->CloseTab();
53 browser()->ActivateTabAt(0, true);
54 browser()->CloseTab();
55
56 ui_test_utils::NavigateToURL(browser(), url);
57
58 EXPECT_EQ(
59 WebCacheManager::GetInstance()->active_renderers_.size(), 1U);
60 EXPECT_EQ(
61 WebCacheManager::GetInstance()->inactive_renderers_.size(), 0U);
62 EXPECT_EQ(
63 WebCacheManager::GetInstance()->stats_.size(), 1U);
64 }
65