blob: 05aeb760d5e590d036ad890075741fc25537f4cf [file] [log] [blame]
[email protected]c2d986512012-05-12 00:22:461// Copyright (c) 2012 The Chromium Authors. All rights reserved.
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commitf5b16fe2008-07-27 00:20:514
5#include "base/file_util.h"
6#include "base/path_service.h"
7#include "base/string_util.h"
[email protected]be1ce6a72010-08-03 14:35:228#include "base/utf_string_conversions.h"
initial.commitf5b16fe2008-07-27 00:20:519#include "net/base/net_util.h"
10#include "net/url_request/url_request_context.h"
[email protected]c1d9cdc2011-01-17 06:50:0111#include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
initial.commitf5b16fe2008-07-27 00:20:5112#include "webkit/glue/dom_operations.h"
initial.commitf5b16fe2008-07-27 00:20:5113#include "webkit/tools/test_shell/simple_resource_loader_bridge.h"
14#include "webkit/tools/test_shell/test_shell_test.h"
15
16namespace {
17
18class DomOperationsTests : public TestShellTest {
19 public:
20 // Test function GetAllSavableResourceLinksForCurrentPage with a web page.
21 // We expect result of GetAllSavableResourceLinksForCurrentPage exactly
22 // matches expected_resources_set.
[email protected]72cbd322009-04-07 10:17:1223 void GetSavableResourceLinksForPage(const FilePath& page_file_path,
initial.commitf5b16fe2008-07-27 00:20:5124 const std::set<GURL>& expected_resources_set);
25
26 protected:
27 // testing::Test
28 virtual void SetUp() {
29 TestShellTest::SetUp();
30 }
31
32 virtual void TearDown() {
33 TestShellTest::TearDown();
34 }
35};
36
initial.commitf5b16fe2008-07-27 00:20:5137
38void DomOperationsTests::GetSavableResourceLinksForPage(
[email protected]72cbd322009-04-07 10:17:1239 const FilePath& page_file_path,
initial.commitf5b16fe2008-07-27 00:20:5140 const std::set<GURL>& expected_resources_set) {
41 // Convert local file path to file URL.
[email protected]8ac1a752008-07-31 19:40:3742 GURL file_url = net::FilePathToFileURL(page_file_path);
initial.commitf5b16fe2008-07-27 00:20:5143 // Load the test file.
44 test_shell_->ResetTestController();
[email protected]3d9689372009-09-10 04:29:1745 test_shell_->LoadURL(file_url);
initial.commitf5b16fe2008-07-27 00:20:5146 test_shell_->WaitTestFinished();
47 // Get all savable resource links for the page.
48 std::vector<GURL> resources_list;
[email protected]c2d986512012-05-12 00:22:4649 std::vector<GURL> referrer_urls_list;
50 std::vector<WebKit::WebReferrerPolicy> referrer_policies_list;
initial.commitf5b16fe2008-07-27 00:20:5151 std::vector<GURL> frames_list;
52 webkit_glue::SavableResourcesResult result(&resources_list,
[email protected]c2d986512012-05-12 00:22:4653 &referrer_urls_list,
54 &referrer_policies_list,
initial.commitf5b16fe2008-07-27 00:20:5155 &frames_list);
56
[email protected]dbeb3952009-10-13 18:01:1857 const char* savable_schemes[] = {
58 "http",
59 "https",
60 "file",
61 NULL
62 };
63
initial.commitf5b16fe2008-07-27 00:20:5164 ASSERT_TRUE(webkit_glue::GetAllSavableResourceLinksForCurrentPage(
[email protected]dbeb3952009-10-13 18:01:1865 test_shell_->webView(), file_url, &result, savable_schemes));
initial.commitf5b16fe2008-07-27 00:20:5166 // Check all links of sub-resource
67 for (std::vector<GURL>::const_iterator cit = resources_list.begin();
68 cit != resources_list.end(); ++cit) {
69 ASSERT_TRUE(expected_resources_set.find(*cit) !=
70 expected_resources_set.end());
71 }
72 // Check all links of frame.
73 for (std::vector<GURL>::const_iterator cit = frames_list.begin();
74 cit != frames_list.end(); ++cit) {
75 ASSERT_TRUE(expected_resources_set.find(*cit) !=
76 expected_resources_set.end());
77 }
78}
79
80// Test function GetAllSavableResourceLinksForCurrentPage with a web page
81// which has valid savable resource links.
82TEST_F(DomOperationsTests, GetSavableResourceLinksWithPageHasValidLinks) {
83 std::set<GURL> expected_resources_set;
84 // Set directory of test data.
[email protected]72cbd322009-04-07 10:17:1285 FilePath page_file_path = data_dir_.AppendASCII("dom_serializer");
initial.commitf5b16fe2008-07-27 00:20:5186
[email protected]a48146712008-11-06 17:51:2087 const char* expected_sub_resource_links[] = {
88 "file:///c:/yt/css/base_all-vfl36460.css",
89 "file:///c:/yt/js/base_all_with_bidi-vfl36451.js",
90 "file:///c:/yt/img/pixel-vfl73.gif"
initial.commitf5b16fe2008-07-27 00:20:5191 };
[email protected]72cbd322009-04-07 10:17:1292 const char* expected_frame_links[] = {
93 "youtube_1.htm",
94 "youtube_2.htm"
initial.commitf5b16fe2008-07-27 00:20:5195 };
96 // Add all expected links of sub-resource to expected set.
[email protected]a48146712008-11-06 17:51:2097 for (size_t i = 0; i < arraysize(expected_sub_resource_links); ++i)
initial.commitf5b16fe2008-07-27 00:20:5198 expected_resources_set.insert(GURL(expected_sub_resource_links[i]));
99 // Add all expected links of frame to expected set.
[email protected]a48146712008-11-06 17:51:20100 for (size_t i = 0; i < arraysize(expected_frame_links); ++i) {
[email protected]72cbd322009-04-07 10:17:12101 const FilePath expected_frame_url =
102 page_file_path.AppendASCII(expected_frame_links[i]);
initial.commitf5b16fe2008-07-27 00:20:51103 expected_resources_set.insert(
[email protected]8ac1a752008-07-31 19:40:37104 net::FilePathToFileURL(expected_frame_url));
initial.commitf5b16fe2008-07-27 00:20:51105 }
106
[email protected]72cbd322009-04-07 10:17:12107 page_file_path = page_file_path.AppendASCII("youtube_1.htm");
initial.commitf5b16fe2008-07-27 00:20:51108 GetSavableResourceLinksForPage(page_file_path, expected_resources_set);
109}
110
111// Test function GetAllSavableResourceLinksForCurrentPage with a web page
112// which does not have valid savable resource links.
113TEST_F(DomOperationsTests, GetSavableResourceLinksWithPageHasInvalidLinks) {
114 std::set<GURL> expected_resources_set;
115 // Set directory of test data.
[email protected]72cbd322009-04-07 10:17:12116 FilePath page_file_path = data_dir_.AppendASCII("dom_serializer");
initial.commitf5b16fe2008-07-27 00:20:51117
[email protected]72cbd322009-04-07 10:17:12118 const char* expected_frame_links[] = {
119 "youtube_2.htm"
initial.commitf5b16fe2008-07-27 00:20:51120 };
121 // Add all expected links of frame to expected set.
[email protected]a48146712008-11-06 17:51:20122 for (size_t i = 0; i < arraysize(expected_frame_links); ++i) {
[email protected]72cbd322009-04-07 10:17:12123 FilePath expected_frame_url =
124 page_file_path.AppendASCII(expected_frame_links[i]);
initial.commitf5b16fe2008-07-27 00:20:51125 expected_resources_set.insert(
[email protected]8ac1a752008-07-31 19:40:37126 net::FilePathToFileURL(expected_frame_url));
initial.commitf5b16fe2008-07-27 00:20:51127 }
128
[email protected]72cbd322009-04-07 10:17:12129 page_file_path = page_file_path.AppendASCII("youtube_2.htm");
initial.commitf5b16fe2008-07-27 00:20:51130 GetSavableResourceLinksForPage(page_file_path, expected_resources_set);
131}
132
[email protected]a03c3ab2008-12-10 20:04:09133} // namespace