OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 #include "chrome/browser/data_usage/tab_id_annotator.h" | 5 #include "chrome/browser/data_usage/tab_id_annotator.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include <memory> | 9 #include <memory> |
10 #include <string> | 10 #include <string> |
11 #include <utility> | 11 #include <utility> |
12 | 12 |
13 #include "base/bind.h" | 13 #include "base/bind.h" |
14 #include "base/callback.h" | 14 #include "base/callback.h" |
15 #include "base/location.h" | 15 #include "base/location.h" |
16 #include "base/macros.h" | 16 #include "base/macros.h" |
17 #include "base/run_loop.h" | 17 #include "base/run_loop.h" |
18 #include "base/time/time.h" | 18 #include "base/time/time.h" |
19 #include "chrome/browser/sessions/session_tab_helper.h" | 19 #include "chrome/browser/sessions/session_tab_helper.h" |
20 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 20 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
21 #include "components/data_usage/core/data_use.h" | 21 #include "components/data_usage/core/data_use.h" |
22 #include "content/public/browser/browser_thread.h" | 22 #include "content/public/browser/browser_thread.h" |
23 #include "content/public/browser/render_frame_host.h" | 23 #include "content/public/browser/render_frame_host.h" |
24 #include "content/public/browser/render_process_host.h" | 24 #include "content/public/browser/render_process_host.h" |
25 #include "content/public/browser/resource_request_info.h" | 25 #include "content/public/browser/resource_request_info.h" |
26 #include "content/public/browser/web_contents.h" | 26 #include "content/public/browser/web_contents.h" |
| 27 #include "content/public/common/previews_state.h" |
27 #include "net/base/network_change_notifier.h" | 28 #include "net/base/network_change_notifier.h" |
28 #include "net/base/request_priority.h" | 29 #include "net/base/request_priority.h" |
29 #include "net/url_request/url_request.h" | 30 #include "net/url_request/url_request.h" |
30 #include "net/url_request/url_request_test_util.h" | 31 #include "net/url_request/url_request_test_util.h" |
31 #include "testing/gtest/include/gtest/gtest.h" | 32 #include "testing/gtest/include/gtest/gtest.h" |
32 #include "url/gurl.h" | 33 #include "url/gurl.h" |
33 | 34 |
34 using content::BrowserThread; | 35 using content::BrowserThread; |
35 using data_usage::DataUse; | 36 using data_usage::DataUse; |
36 | 37 |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 net::TestDelegate test_delegate; | 100 net::TestDelegate test_delegate; |
100 std::unique_ptr<net::URLRequest> request = | 101 std::unique_ptr<net::URLRequest> request = |
101 context.CreateRequest(GURL("http://foo.com"), net::IDLE, &test_delegate); | 102 context.CreateRequest(GURL("http://foo.com"), net::IDLE, &test_delegate); |
102 | 103 |
103 if (render_process_id != -1 && render_frame_id != -1) { | 104 if (render_process_id != -1 && render_frame_id != -1) { |
104 // The only args that matter here for the ResourceRequestInfo are the | 105 // The only args that matter here for the ResourceRequestInfo are the |
105 // |request|, the |render_process_id|, and the |render_frame_id|; arbitrary | 106 // |request|, the |render_process_id|, and the |render_frame_id|; arbitrary |
106 // values are used for all the other args. | 107 // values are used for all the other args. |
107 content::ResourceRequestInfo::AllocateForTesting( | 108 content::ResourceRequestInfo::AllocateForTesting( |
108 request.get(), content::RESOURCE_TYPE_MAIN_FRAME, nullptr, | 109 request.get(), content::RESOURCE_TYPE_MAIN_FRAME, nullptr, |
109 render_process_id, -1, render_frame_id, true, false, true, true, false); | 110 render_process_id, -1, render_frame_id, true, false, true, true, |
| 111 content::PREVIEWS_OFF); |
110 } | 112 } |
111 | 113 |
112 // An invalid tab ID to check that the annotator always sets the tab ID. -2 is | 114 // An invalid tab ID to check that the annotator always sets the tab ID. -2 is |
113 // used because a tab ID of -1 is a valid value that means "no tab was found". | 115 // used because a tab ID of -1 is a valid value that means "no tab was found". |
114 const int32_t kInvalidTabId = -2; | 116 const int32_t kInvalidTabId = -2; |
115 | 117 |
116 // Annotate two separate DataUse objects to ensure that repeated annotations | 118 // Annotate two separate DataUse objects to ensure that repeated annotations |
117 // for the same URLRequest work properly. | 119 // for the same URLRequest work properly. |
118 std::unique_ptr<DataUse> first_expected_data_use = | 120 std::unique_ptr<DataUse> first_expected_data_use = |
119 CreateDataUse(expected_tab_id); | 121 CreateDataUse(expected_tab_id); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 base::Bind(&TestAnnotateOnIOThread, &ui_run_loop, | 168 base::Bind(&TestAnnotateOnIOThread, &ui_run_loop, |
167 web_contents()->GetMainFrame()->GetProcess()->GetID(), | 169 web_contents()->GetMainFrame()->GetProcess()->GetID(), |
168 web_contents()->GetMainFrame()->GetRoutingID(), | 170 web_contents()->GetMainFrame()->GetRoutingID(), |
169 expected_tab_id)); | 171 expected_tab_id)); |
170 ui_run_loop.Run(); | 172 ui_run_loop.Run(); |
171 } | 173 } |
172 | 174 |
173 } // namespace | 175 } // namespace |
174 | 176 |
175 } // namespace chrome_browser_data_usage | 177 } // namespace chrome_browser_data_usage |
OLD | NEW |