Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(594)

Side by Side Diff: chrome/browser/metrics/metrics_service_uitest.cc

Issue 113722: Make automation proxy objects to ref_counted. That allows to process async no... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Tests the MetricsService stat recording to make sure that the numbers are 5 // Tests the MetricsService stat recording to make sure that the numbers are
6 // what we expect. 6 // what we expect.
7 7
8 #include <string> 8 #include <string>
9 9
10 #include "base/file_path.h" 10 #include "base/file_path.h"
11 #include "base/file_util.h" 11 #include "base/file_util.h"
12 #include "base/path_service.h" 12 #include "base/path_service.h"
13 #include "base/platform_thread.h" 13 #include "base/platform_thread.h"
14 #include "base/process_util.h" 14 #include "base/process_util.h"
15 #include "chrome/app/chrome_dll_resource.h" 15 #include "chrome/app/chrome_dll_resource.h"
16 #include "chrome/common/chrome_constants.h" 16 #include "chrome/common/chrome_constants.h"
17 #include "chrome/common/chrome_paths.h" 17 #include "chrome/common/chrome_paths.h"
18 #include "chrome/common/pref_names.h" 18 #include "chrome/common/pref_names.h"
19 #include "chrome/common/pref_service.h" 19 #include "chrome/common/pref_service.h"
20 #include "chrome/test/automation/tab_proxy.h" 20 #include "chrome/test/automation/tab_proxy.h"
21 #include "chrome/test/automation/browser_proxy.h" 21 #include "chrome/test/automation/browser_proxy.h"
22 #include "chrome/test/ui/ui_test.h" 22 #include "chrome/test/ui/ui_test.h"
23 #include "net/base/net_util.h" 23 #include "net/base/net_util.h"
24 24
25 class MetricsServiceTest : public UITest { 25 class MetricsServiceTest : public UITest {
26 public: 26 public:
27 MetricsServiceTest() : UITest(), window_(NULL) { 27 MetricsServiceTest() : UITest() {
28 // We need to show the window so web content type tabs load. 28 // We need to show the window so web content type tabs load.
29 show_window_ = true; 29 show_window_ = true;
30 } 30 }
31 31
32 // Open a few tabs of random content 32 // Open a few tabs of random content
33 void OpenTabs() { 33 void OpenTabs() {
34 window_ = automation()->GetBrowserWindow(0); 34 window_ = automation()->GetBrowserWindow(0);
35 ASSERT_TRUE(window_); 35 ASSERT_TRUE(window_.get());
36 36
37 FilePath page1_path; 37 FilePath page1_path;
38 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &page1_path)); 38 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &page1_path));
39 page1_path = page1_path.AppendASCII("title2.html"); 39 page1_path = page1_path.AppendASCII("title2.html");
40 ASSERT_TRUE(window_->AppendTab(net::FilePathToFileURL(page1_path))); 40 ASSERT_TRUE(window_->AppendTab(net::FilePathToFileURL(page1_path)));
41 41
42 FilePath page2_path; 42 FilePath page2_path;
43 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &page2_path)); 43 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &page2_path));
44 page2_path = page2_path.AppendASCII("iframe.html"); 44 page2_path = page2_path.AppendASCII("iframe.html");
45 ASSERT_TRUE(window_->AppendTab(net::FilePathToFileURL(page2_path))); 45 ASSERT_TRUE(window_->AppendTab(net::FilePathToFileURL(page2_path)));
46 } 46 }
47 47
48 // Get a PrefService whose contents correspond to the Local State file 48 // Get a PrefService whose contents correspond to the Local State file
49 // that was saved by the app as it closed. The caller takes ownership of the 49 // that was saved by the app as it closed. The caller takes ownership of the
50 // returned PrefService object. 50 // returned PrefService object.
51 PrefService* GetLocalState() { 51 PrefService* GetLocalState() {
52 FilePath local_state_path = user_data_dir() 52 FilePath local_state_path = user_data_dir()
53 .Append(chrome::kLocalStateFilename); 53 .Append(chrome::kLocalStateFilename);
54 54
55 PrefService* local_state(new PrefService(local_state_path, NULL)); 55 PrefService* local_state(new PrefService(local_state_path, NULL));
56 return local_state; 56 return local_state;
57 } 57 }
58 58
59 virtual void TearDown() { 59 virtual void TearDown() {
60 delete window_; 60 window_ = NULL;
61 UITest::TearDown(); 61 UITest::TearDown();
62 } 62 }
63 63
64 protected: 64 protected:
65 BrowserProxy* window_; 65 scoped_refptr<BrowserProxy> window_;
66 }; 66 };
67 67
68 TEST_F(MetricsServiceTest, CloseRenderersNormally) { 68 TEST_F(MetricsServiceTest, CloseRenderersNormally) {
69 OpenTabs(); 69 OpenTabs();
70 QuitBrowser(); 70 QuitBrowser();
71 71
72 scoped_ptr<PrefService> local_state(GetLocalState()); 72 scoped_ptr<PrefService> local_state(GetLocalState());
73 local_state->RegisterBooleanPref(prefs::kStabilityExitedCleanly, true); 73 local_state->RegisterBooleanPref(prefs::kStabilityExitedCleanly, true);
74 local_state->RegisterIntegerPref(prefs::kStabilityLaunchCount, 0); 74 local_state->RegisterIntegerPref(prefs::kStabilityLaunchCount, 0);
75 local_state->RegisterIntegerPref(prefs::kStabilityPageLoadCount, 0); 75 local_state->RegisterIntegerPref(prefs::kStabilityPageLoadCount, 0);
76 local_state->RegisterIntegerPref(prefs::kStabilityRendererCrashCount, 0); 76 local_state->RegisterIntegerPref(prefs::kStabilityRendererCrashCount, 0);
77 EXPECT_TRUE(local_state->GetBoolean(prefs::kStabilityExitedCleanly)); 77 EXPECT_TRUE(local_state->GetBoolean(prefs::kStabilityExitedCleanly));
78 EXPECT_EQ(1, local_state->GetInteger(prefs::kStabilityLaunchCount)); 78 EXPECT_EQ(1, local_state->GetInteger(prefs::kStabilityLaunchCount));
79 EXPECT_EQ(3, local_state->GetInteger(prefs::kStabilityPageLoadCount)); 79 EXPECT_EQ(3, local_state->GetInteger(prefs::kStabilityPageLoadCount));
80 EXPECT_EQ(0, local_state->GetInteger(prefs::kStabilityRendererCrashCount)); 80 EXPECT_EQ(0, local_state->GetInteger(prefs::kStabilityRendererCrashCount));
81 } 81 }
82 82
83 TEST_F(MetricsServiceTest, CrashRenderers) { 83 TEST_F(MetricsServiceTest, CrashRenderers) {
84 // This doesn't make sense to test in single process mode. 84 // This doesn't make sense to test in single process mode.
85 if (in_process_renderer_) 85 if (in_process_renderer_)
86 return; 86 return;
87 87
88 OpenTabs(); 88 OpenTabs();
89 89
90 // kill the process for one of the tabs 90 // kill the process for one of the tabs
91 scoped_ptr<TabProxy> tab(window_->GetTab(1)); 91 scoped_refptr<TabProxy> tab(window_->GetTab(1));
92 ASSERT_TRUE(tab.get()); 92 ASSERT_TRUE(tab.get());
93 int process_id = 0; 93 int process_id = 0;
94 ASSERT_TRUE(tab->GetProcessID(&process_id)); 94 ASSERT_TRUE(tab->GetProcessID(&process_id));
95 ASSERT_NE(0, process_id); 95 ASSERT_NE(0, process_id);
96 base::ProcessHandle process_handle; 96 base::ProcessHandle process_handle;
97 ASSERT_TRUE(base::OpenProcessHandle(process_id, &process_handle)); 97 ASSERT_TRUE(base::OpenProcessHandle(process_id, &process_handle));
98 // Fake Access Violation. 98 // Fake Access Violation.
99 base::KillProcess(process_handle, 0xc0000005, true); 99 base::KillProcess(process_handle, 0xc0000005, true);
100 base::CloseProcessHandle(process_handle); 100 base::CloseProcessHandle(process_handle);
101 101
102 // Give the browser a chance to notice the crashed tab. 102 // Give the browser a chance to notice the crashed tab.
103 PlatformThread::Sleep(1000); 103 PlatformThread::Sleep(1000);
104 104
105 QuitBrowser(); 105 QuitBrowser();
106 106
107 scoped_ptr<PrefService> local_state(GetLocalState()); 107 scoped_ptr<PrefService> local_state(GetLocalState());
108 local_state->RegisterBooleanPref(prefs::kStabilityExitedCleanly, true); 108 local_state->RegisterBooleanPref(prefs::kStabilityExitedCleanly, true);
109 local_state->RegisterIntegerPref(prefs::kStabilityLaunchCount, 0); 109 local_state->RegisterIntegerPref(prefs::kStabilityLaunchCount, 0);
110 local_state->RegisterIntegerPref(prefs::kStabilityPageLoadCount, 0); 110 local_state->RegisterIntegerPref(prefs::kStabilityPageLoadCount, 0);
111 local_state->RegisterIntegerPref(prefs::kStabilityRendererCrashCount, 0); 111 local_state->RegisterIntegerPref(prefs::kStabilityRendererCrashCount, 0);
112 EXPECT_TRUE(local_state->GetBoolean(prefs::kStabilityExitedCleanly)); 112 EXPECT_TRUE(local_state->GetBoolean(prefs::kStabilityExitedCleanly));
113 EXPECT_EQ(1, local_state->GetInteger(prefs::kStabilityLaunchCount)); 113 EXPECT_EQ(1, local_state->GetInteger(prefs::kStabilityLaunchCount));
114 EXPECT_EQ(3, local_state->GetInteger(prefs::kStabilityPageLoadCount)); 114 EXPECT_EQ(3, local_state->GetInteger(prefs::kStabilityPageLoadCount));
115 EXPECT_EQ(1, local_state->GetInteger(prefs::kStabilityRendererCrashCount)); 115 EXPECT_EQ(1, local_state->GetInteger(prefs::kStabilityRendererCrashCount));
116 } 116 }
OLDNEW
« no previous file with comments | « chrome/browser/login_prompt_uitest.cc ('k') | chrome/browser/printing/printing_layout_uitest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698