Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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_use_measurement/chrome_data_use_ascriber.h" | 5 #include "chrome/browser/data_use_measurement/chrome_data_use_ascriber.h" |
| 6 | 6 |
| 7 #include <list> | 7 #include <list> |
| 8 #include <memory> | 8 #include <memory> |
| 9 | 9 |
| 10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| 11 #include "base/run_loop.h" | 11 #include "base/run_loop.h" |
| 12 #include "components/data_use_measurement/core/data_use_recorder.h" | 12 #include "components/data_use_measurement/core/data_use_recorder.h" |
| 13 #include "content/public/browser/resource_request_info.h" | 13 #include "content/public/browser/resource_request_info.h" |
| 14 #include "content/public/common/browser_side_navigation_policy.h" | 14 #include "content/public/common/browser_side_navigation_policy.h" |
| 15 #include "content/public/common/previews_state.h" | |
| 15 #include "content/public/common/process_type.h" | 16 #include "content/public/common/process_type.h" |
| 16 #include "content/public/test/mock_resource_context.h" | 17 #include "content/public/test/mock_resource_context.h" |
| 17 #include "content/public/test/test_browser_thread_bundle.h" | 18 #include "content/public/test/test_browser_thread_bundle.h" |
| 18 #include "net/url_request/url_request_test_util.h" | 19 #include "net/url_request/url_request_test_util.h" |
| 19 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
| 20 | 21 |
| 21 namespace { | 22 namespace { |
| 22 int kRenderProcessId = 1; | 23 int kRenderProcessId = 1; |
| 23 int kRenderFrameId = 2; | 24 int kRenderFrameId = 2; |
| 24 int kRequestId = 3; | 25 int kRequestId = 3; |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 50 | 51 |
| 51 std::unique_ptr<net::URLRequest> CreateNewRequest(std::string url, | 52 std::unique_ptr<net::URLRequest> CreateNewRequest(std::string url, |
| 52 bool is_main_frame, | 53 bool is_main_frame, |
| 53 int request_id, | 54 int request_id, |
| 54 int render_process_id, | 55 int render_process_id, |
| 55 int render_frame_id) { | 56 int render_frame_id) { |
| 56 std::unique_ptr<net::URLRequest> request = | 57 std::unique_ptr<net::URLRequest> request = |
| 57 context()->CreateRequest(GURL(url), net::IDLE, nullptr); | 58 context()->CreateRequest(GURL(url), net::IDLE, nullptr); |
| 58 // TODO(kundaji): Allow request_id to be specified in AllocateForTesting. | 59 // TODO(kundaji): Allow request_id to be specified in AllocateForTesting. |
| 59 content::ResourceRequestInfo::AllocateForTesting( | 60 content::ResourceRequestInfo::AllocateForTesting( |
| 60 request.get(), | 61 request.get(), content::RESOURCE_TYPE_MAIN_FRAME, resource_context(), |
| 61 content::RESOURCE_TYPE_MAIN_FRAME, | |
| 62 resource_context(), | |
| 63 render_process_id, | 62 render_process_id, |
| 64 -1, // render_view_id | 63 -1, // render_view_id |
| 65 render_frame_id, | 64 render_frame_id, is_main_frame, |
| 66 is_main_frame, | 65 false, // parent_is_main_frame |
| 67 false, // parent_is_main_frame | 66 false, // allow_download |
| 68 false, // allow_download | 67 true, // is_async |
| 69 true, // is_async | 68 content::PREVIEWS_OFF); // previews_state |
|
Nico
2017/01/09 22:35:03
nit: remove now-useless comment for PREVIEWS_OFF
megjablon
2017/01/10 22:30:01
Done.
| |
| 70 false); // is_using_lofi | |
| 71 return request; | 69 return request; |
| 72 } | 70 } |
| 73 | 71 |
| 74 private: | 72 private: |
| 75 content::TestBrowserThreadBundle thread_bundle_; | 73 content::TestBrowserThreadBundle thread_bundle_; |
| 76 ChromeDataUseAscriber ascriber_; | 74 ChromeDataUseAscriber ascriber_; |
| 77 net::TestURLRequestContext context_; | 75 net::TestURLRequestContext context_; |
| 78 std::unique_ptr<content::MockResourceContext> resource_context_; | 76 std::unique_ptr<content::MockResourceContext> resource_context_; |
| 79 }; | 77 }; |
| 80 | 78 |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 95 EXPECT_EQ(1u, recorders().size()); | 93 EXPECT_EQ(1u, recorders().size()); |
| 96 | 94 |
| 97 // Request should cause a recorder to be created. | 95 // Request should cause a recorder to be created. |
| 98 ascriber()->OnBeforeUrlRequest(request.get()); | 96 ascriber()->OnBeforeUrlRequest(request.get()); |
| 99 EXPECT_EQ(2u, recorders().size()); | 97 EXPECT_EQ(2u, recorders().size()); |
| 100 | 98 |
| 101 ascriber()->RenderFrameDeleted(kRenderProcessId, kRenderFrameId, -1, -1); | 99 ascriber()->RenderFrameDeleted(kRenderProcessId, kRenderFrameId, -1, -1); |
| 102 } | 100 } |
| 103 | 101 |
| 104 } // namespace data_use_measurement | 102 } // namespace data_use_measurement |
| OLD | NEW |