1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
|
// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "base/scoped_ptr.h"
#include "chrome/browser/page_load_tracker.h"
#include "chrome/browser/tab_contents.h"
#include "chrome/browser/tab_util.h"
#include "chrome/browser/web_contents.h"
#include "chrome/common/gfx/chrome_canvas.h"
#include "chrome/views/background.h"
#include "chrome/views/root_view.h"
#include "net/url_request/url_request.h"
#include "net/url_request/url_request_job.h"
#include "net/url_request/url_request_job_metrics.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace {
PageLoadTracker* CreateSamplePage(TimeTicks start_time, bool success) {
std::string url_str("www.google.com");
GURL url(url_str);
int render_process_host_id = 10;
int routing_id = 10;
TimeDelta increment = TimeDelta::FromMicroseconds(100);
PageLoadTracker* page = new PageLoadTracker(url, render_process_host_id,
routing_id, start_time);
// Add frames
int32 page_id = 1;
FrameNavigationMetrics* frame =
new FrameNavigationMetrics(PageTransition::TYPED,
start_time + increment,
url,
page_id);
page->AddFrameMetrics(frame);
frame = new FrameNavigationMetrics(PageTransition::AUTO_SUBFRAME,
start_time + 2*increment,
url,
page_id);
page->AddFrameMetrics(frame);
frame = new FrameNavigationMetrics(PageTransition::AUTO_SUBFRAME,
start_time + 3*increment,
url,
page_id);
page->AddFrameMetrics(frame);
if (success) {
page->SetLoadingEndTime(page_id, start_time + 4*increment);
}
// Add JobMetrics
int total_bytes_read = 1000;
int number_of_read_IO = 3;
URLRequestJobMetrics* job = new URLRequestJobMetrics();
job->total_bytes_read_ = total_bytes_read;
job->number_of_read_IO_ = number_of_read_IO;
job->start_time_ = start_time + TimeDelta::FromMicroseconds(150);
job->end_time_ = start_time + TimeDelta::FromMicroseconds(350);
page->AddJobMetrics(job);
job = new URLRequestJobMetrics();
job->total_bytes_read_ = total_bytes_read + 500;
job->number_of_read_IO_ = number_of_read_IO + 2;
job->start_time_ = start_time + TimeDelta::FromMicroseconds(250);
job->end_time_ = start_time + TimeDelta::FromMicroseconds(350);
page->AddJobMetrics(job);
return page;
}
class TestView : public ChromeViews::View {
public:
virtual void Paint(ChromeCanvas* canvas) {
CRect lb;
GetLocalBounds(&lb, true);
page_->Draw(lb, canvas);
}
void SetPage(PageLoadTracker* page) {
page_.reset(page);
}
private:
scoped_ptr<PageLoadTracker> page_;
};
} // namespace
TEST(PageLoadTrackerUnitTest, AddMetrics) {
TimeTicks start_time = TimeTicks::Now();
scoped_ptr<PageLoadTracker> page(CreateSamplePage(start_time, true));
// Verify
EXPECT_EQ(3, page->frame_metrics_list_.size());
EXPECT_EQ(2, page->job_metrics_list_.size());
EXPECT_TRUE(start_time + TimeDelta::FromMicroseconds(400)
== page->stop_time());
}
#if 0
TEST(PageLoadTrackerUnitTest, ViewFailedPage) {
ChromeViews::Window window;
window.set_delete_on_destroy(false);
window.set_window_style(WS_OVERLAPPEDWINDOW);
window.Init(NULL, gfx::Rect(50, 50, 650, 650), NULL, NULL);
ChromeViews::RootView* root = window.GetRootView();
TestView* view = new TestView();
CRect lb;
root->AddChildView(view);
root->GetLocalBounds(&lb);
view->SetBounds(lb);
view->SetPage(CreateSamplePage(20000, false));
root->PaintNow();
Sleep(1000);
window.DestroyWindow();
}
TEST(PageLoadTrackerUnitTest, ViewSuccessPage) {
ChromeViews::Window window;
window.set_delete_on_destroy(false);
window.set_window_style(WS_OVERLAPPEDWINDOW);
window.Init(NULL, gfx::Rect(50, 50, 650, 650), NULL, NULL);
ChromeViews::RootView* root = window.GetRootView();
TestView* view = new TestView();
CRect lb;
root->AddChildView(view);
root->GetLocalBounds(&lb);
view->SetBounds(lb);
view->SetPage(CreateSamplePage(20000, true));
root->PaintNow();
Sleep(1000);
window.DestroyWindow();
}
#endif
|