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

Side by Side Diff: content/renderer/savable_resources_browsertest.cc

Issue 1308113008: OOPIFs: Transitioning Get/Send...SavableResourceLinks away from RenderViewHost. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@page-serialization-test
Patch Set: Fixed savable_resources_browsertest.cc to use RenderFrame rather than RenderView. Created 5 years, 3 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
« no previous file with comments | « content/renderer/savable_resources.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "base/bind.h" 5 #include "base/bind.h"
6 #include "base/command_line.h" 6 #include "base/command_line.h"
7 #include "base/files/file_path.h" 7 #include "base/files/file_path.h"
8 #include "content/public/browser/render_frame_host.h"
8 #include "content/public/browser/web_contents.h" 9 #include "content/public/browser/web_contents.h"
9 #include "content/public/common/content_switches.h" 10 #include "content/public/common/content_switches.h"
10 #include "content/public/renderer/render_view.h" 11 #include "content/public/renderer/render_frame.h"
11 #include "content/public/test/content_browser_test.h" 12 #include "content/public/test/content_browser_test.h"
12 #include "content/public/test/content_browser_test_utils.h" 13 #include "content/public/test/content_browser_test_utils.h"
13 #include "content/renderer/savable_resources.h" 14 #include "content/renderer/savable_resources.h"
14 #include "content/shell/browser/shell.h" 15 #include "content/shell/browser/shell.h"
15 #include "net/base/filename_util.h" 16 #include "net/base/filename_util.h"
17 #include "third_party/WebKit/public/web/WebLocalFrame.h"
16 18
17 namespace content { 19 namespace content {
18 20
19 class SavableResourcesTest : public ContentBrowserTest { 21 class SavableResourcesTest : public ContentBrowserTest {
20 public: 22 public:
21 void SetUpCommandLine(base::CommandLine* command_line) override { 23 void SetUpCommandLine(base::CommandLine* command_line) override {
22 command_line->AppendSwitch(switches::kSingleProcess); 24 command_line->AppendSwitch(switches::kSingleProcess);
23 #if defined(OS_WIN) 25 #if defined(OS_WIN)
24 // Don't want to try to create a GPU process. 26 // Don't want to try to create a GPU process.
25 command_line->AppendSwitch(switches::kDisableGpu); 27 command_line->AppendSwitch(switches::kDisableGpu);
26 #endif 28 #endif
27 } 29 }
28 30
29 // Test function GetAllSavableResourceLinksForCurrentPage with a web page. 31 // Test function GetAllSavableResourceLinksForCurrentPage with a web page.
30 // We expect result of GetAllSavableResourceLinksForCurrentPage exactly 32 // We expect result of GetAllSavableResourceLinksForCurrentPage exactly
31 // matches expected_resources_set. 33 // matches expected_resources_set.
32 void GetSavableResourceLinksForPage( 34 void GetSavableResourceLinksForPage(
33 const base::FilePath& page_file_path, 35 const base::FilePath& page_file_path,
34 const std::set<GURL>& expected_resources_set) { 36 const std::set<GURL>& expected_resources_set) {
35 // Convert local file path to file URL. 37 // Convert local file path to file URL.
36 GURL file_url = net::FilePathToFileURL(page_file_path); 38 GURL file_url = net::FilePathToFileURL(page_file_path);
37 // Load the test file. 39 // Load the test file.
38 NavigateToURL(shell(), file_url); 40 NavigateToURL(shell(), file_url);
39 41
40 PostTaskToInProcessRendererAndWait( 42 PostTaskToInProcessRendererAndWait(base::Bind(
41 base::Bind(&SavableResourcesTest::CheckResources, 43 &SavableResourcesTest::CheckResources, base::Unretained(this),
42 base::Unretained(this), 44 page_file_path, expected_resources_set, file_url,
43 page_file_path, 45 shell()->web_contents()->GetMainFrame()->GetRoutingID()));
44 expected_resources_set,
45 file_url,
46 shell()->web_contents()->GetRoutingID()));
47 } 46 }
48 47
49 void CheckResources(const base::FilePath& page_file_path, 48 void CheckResources(const base::FilePath& page_file_path,
50 const std::set<GURL>& expected_resources_set, 49 const std::set<GURL>& expected_resources_set,
51 const GURL& file_url, 50 const GURL& file_url,
52 int render_view_id) { 51 int render_frame_routing_id) {
53 // Get all savable resource links for the page. 52 // Get all savable resource links for the page.
54 std::vector<GURL> resources_list; 53 std::vector<GURL> resources_list;
55 std::vector<GURL> referrer_urls_list; 54 std::vector<GURL> referrer_urls_list;
56 std::vector<blink::WebReferrerPolicy> referrer_policies_list; 55 std::vector<blink::WebReferrerPolicy> referrer_policies_list;
57 std::vector<GURL> frames_list; 56 SavableResourcesResult result(&resources_list, &referrer_urls_list,
58 SavableResourcesResult result(&resources_list, 57 &referrer_policies_list);
59 &referrer_urls_list,
60 &referrer_policies_list,
61 &frames_list);
62 58
63 const char* savable_schemes[] = { 59 const char* savable_schemes[] = {
64 "http", 60 "http",
65 "https", 61 "https",
66 "file", 62 "file",
67 NULL 63 NULL
68 }; 64 };
69 65
70 RenderView* render_view = RenderView::FromRoutingID(render_view_id); 66 RenderFrame* render_frame =
67 RenderFrame::FromRoutingID(render_frame_routing_id);
71 68
72 ASSERT_TRUE(GetAllSavableResourceLinksForCurrentPage( 69 ASSERT_TRUE(GetSavableResourceLinksForFrame(
73 render_view->GetWebView(), file_url, &result, savable_schemes)); 70 render_frame->GetWebFrame(),
71 &result, savable_schemes));
74 72
75 // Check all links of sub-resource 73 // Check all links of sub-resource
76 for (std::vector<GURL>::const_iterator cit = resources_list.begin(); 74 for (const auto& resource : resources_list) {
77 cit != resources_list.end(); ++cit) { 75 ASSERT_TRUE(expected_resources_set.count(resource) != 0);
78 ASSERT_TRUE(expected_resources_set.find(*cit) !=
79 expected_resources_set.end());
80 }
81
82 // Check all links of frame.
83 for (std::vector<GURL>::const_iterator cit = frames_list.begin();
84 cit != frames_list.end(); ++cit) {
85 ASSERT_TRUE(expected_resources_set.find(*cit) !=
86 expected_resources_set.end());
87 } 76 }
88 } 77 }
89 }; 78 };
90 79
91 IN_PROC_BROWSER_TEST_F(SavableResourcesTest, 80 IN_PROC_BROWSER_TEST_F(SavableResourcesTest,
92 GetSavableResourceLinksWithPageHasValidStyleLink) { 81 GetSavableResourceLinksWithPageHasValidStyleLink) {
93 const char* expected_sub_resource_links[] = { 82 const char* expected_sub_resource_links[] = {
94 "style.css" 83 "style.css"
95 }; 84 };
96 85
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 expected_resources_set.insert( 152 expected_resources_set.insert(
164 net::FilePathToFileURL(expected_frame_url)); 153 net::FilePathToFileURL(expected_frame_url));
165 } 154 }
166 155
167 base::FilePath page_file_path = 156 base::FilePath page_file_path =
168 GetTestFilePath("dom_serializer", "youtube_2.htm"); 157 GetTestFilePath("dom_serializer", "youtube_2.htm");
169 GetSavableResourceLinksForPage(page_file_path, expected_resources_set); 158 GetSavableResourceLinksForPage(page_file_path, expected_resources_set);
170 } 159 }
171 160
172 } // namespace content 161 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/savable_resources.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698