Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / components / url_fixer / url_fixer_unittest.cc
index fa4e03c..893b75e 100644 (file)
@@ -6,9 +6,9 @@
 
 #include "base/base_paths.h"
 #include "base/basictypes.h"
-#include "base/file_util.h"
 #include "base/files/file_path.h"
-#include "base/path_service.h"
+#include "base/files/file_util.h"
+#include "base/files/scoped_temp_dir.h"
 #include "base/strings/string_util.h"
 #include "base/strings/utf_string_conversions.h"
 #include "components/url_fixer/url_fixer.h"
@@ -321,24 +321,41 @@ TEST(URLFixerTest, FixupURL) {
 
   // Check the TLD-appending functionality.
   FixupCase tld_cases[] = {
-    {"google", "http://www.google.com/"},
-    {"google.", "http://www.google.com/"},
-    {"google..", "http://www.google.com/"},
-    {".google", "http://www.google.com/"},
-    {"www.google", "http://www.google.com/"},
-    {"google.com", "http://google.com/"},
-    {"http://google", "http://www.google.com/"},
-    {"..google..", "http://www.google.com/"},
-    {"http://www.google", "http://www.google.com/"},
-    {"9999999999999999", "http://www.9999999999999999.com/"},
-    {"google/foo", "http://www.google.com/foo"},
-    {"google.com/foo", "http://google.com/foo"},
-    {"google/?foo=.com", "http://www.google.com/?foo=.com"},
-    {"www.google/?foo=www.", "http://www.google.com/?foo=www."},
-    {"google.com/?foo=.com", "http://google.com/?foo=.com"},
-    {"http://www.google.com", "http://www.google.com/"},
-    {"google:123", "http://www.google.com:123/"},
-    {"http://google:123", "http://www.google.com:123/"},
+      {"somedomainthatwillnotbeagtld",
+       "http://www.somedomainthatwillnotbeagtld.com/"},
+      {"somedomainthatwillnotbeagtld.",
+       "http://www.somedomainthatwillnotbeagtld.com/"},
+      {"somedomainthatwillnotbeagtld..",
+       "http://www.somedomainthatwillnotbeagtld.com/"},
+      {".somedomainthatwillnotbeagtld",
+       "http://www.somedomainthatwillnotbeagtld.com/"},
+      {"www.somedomainthatwillnotbeagtld",
+       "http://www.somedomainthatwillnotbeagtld.com/"},
+      {"somedomainthatwillnotbeagtld.com",
+       "http://somedomainthatwillnotbeagtld.com/"},
+      {"http://somedomainthatwillnotbeagtld",
+       "http://www.somedomainthatwillnotbeagtld.com/"},
+      {"..somedomainthatwillnotbeagtld..",
+       "http://www.somedomainthatwillnotbeagtld.com/"},
+      {"http://www.somedomainthatwillnotbeagtld",
+       "http://www.somedomainthatwillnotbeagtld.com/"},
+      {"9999999999999999", "http://www.9999999999999999.com/"},
+      {"somedomainthatwillnotbeagtld/foo",
+       "http://www.somedomainthatwillnotbeagtld.com/foo"},
+      {"somedomainthatwillnotbeagtld.com/foo",
+       "http://somedomainthatwillnotbeagtld.com/foo"},
+      {"somedomainthatwillnotbeagtld/?foo=.com",
+       "http://www.somedomainthatwillnotbeagtld.com/?foo=.com"},
+      {"www.somedomainthatwillnotbeagtld/?foo=www.",
+       "http://www.somedomainthatwillnotbeagtld.com/?foo=www."},
+      {"somedomainthatwillnotbeagtld.com/?foo=.com",
+       "http://somedomainthatwillnotbeagtld.com/?foo=.com"},
+      {"http://www.somedomainthatwillnotbeagtld.com",
+       "http://www.somedomainthatwillnotbeagtld.com/"},
+      {"somedomainthatwillnotbeagtld:123",
+       "http://www.somedomainthatwillnotbeagtld.com:123/"},
+      {"http://somedomainthatwillnotbeagtld:123",
+       "http://www.somedomainthatwillnotbeagtld.com:123/"},
   };
   for (size_t i = 0; i < arraysize(tld_cases); ++i) {
     FixupCase value = tld_cases[i];
@@ -352,11 +369,11 @@ TEST(URLFixerTest, FixupURL) {
 // has to exist.
 TEST(URLFixerTest, FixupFile) {
   // this "original" filename is the one we tweak to get all the variations
-  base::FilePath dir;
+  base::ScopedTempDir temp_dir_;
+  ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
   base::FilePath original;
-  ASSERT_TRUE(PathService::Get(base::DIR_MODULE, &dir));
   ASSERT_TRUE(MakeTempFile(
-      dir,
+      temp_dir_.path(),
       base::FilePath(FILE_PATH_LITERAL("url fixer upper existing file.txt")),
       &original));
 
@@ -435,11 +452,12 @@ TEST(URLFixerTest, FixupFile) {
 }
 
 TEST(URLFixerTest, FixupRelativeFile) {
-  base::FilePath full_path, dir;
+  base::FilePath full_path;
   base::FilePath file_part(
       FILE_PATH_LITERAL("url_fixer_upper_existing_file.txt"));
-  ASSERT_TRUE(PathService::Get(base::DIR_MODULE, &dir));
-  ASSERT_TRUE(MakeTempFile(dir, file_part, &full_path));
+  base::ScopedTempDir temp_dir_;
+  ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
+  ASSERT_TRUE(MakeTempFile(temp_dir_.path(), file_part, &full_path));
   full_path = base::MakeAbsoluteFilePath(full_path);
   ASSERT_FALSE(full_path.empty());
 
@@ -448,22 +466,23 @@ TEST(URLFixerTest, FixupRelativeFile) {
     FixupCase value = fixup_cases[i];
     base::FilePath input = base::FilePath::FromUTF8Unsafe(value.input);
     EXPECT_EQ(value.output,
-              url_fixer::FixupRelativeFile(dir, input).possibly_invalid_spec());
+              url_fixer::FixupRelativeFile(temp_dir_.path(),
+                  input).possibly_invalid_spec());
   }
 
   // make sure the existing file got fixed-up to a file URL, and that there
   // are no backslashes
   EXPECT_TRUE(IsMatchingFileURL(
-      url_fixer::FixupRelativeFile(dir, file_part).possibly_invalid_spec(),
-      full_path));
+      url_fixer::FixupRelativeFile(temp_dir_.path(),
+          file_part).possibly_invalid_spec(), full_path));
   EXPECT_TRUE(base::DeleteFile(full_path, false));
 
   // create a filename we know doesn't exist and make sure it doesn't get
   // fixed up to a file URL
   base::FilePath nonexistent_file(
       FILE_PATH_LITERAL("url_fixer_upper_nonexistent_file.txt"));
-  std::string fixedup(url_fixer::FixupRelativeFile(dir, nonexistent_file)
-                          .possibly_invalid_spec());
+  std::string fixedup(url_fixer::FixupRelativeFile(
+      temp_dir_.path(), nonexistent_file).possibly_invalid_spec());
   EXPECT_NE(std::string("file:///"), fixedup.substr(0, 8));
   EXPECT_FALSE(IsMatchingFileURL(fixedup, nonexistent_file));
 
@@ -473,7 +492,7 @@ TEST(URLFixerTest, FixupRelativeFile) {
   base::FilePath sub_dir(FILE_PATH_LITERAL("url fixer-upper dir"));
   base::FilePath sub_file(
       FILE_PATH_LITERAL("url fixer-upper existing file.txt"));
-  base::FilePath new_dir = dir.Append(sub_dir);
+  base::FilePath new_dir = temp_dir_.path().Append(sub_dir);
   base::CreateDirectory(new_dir);
   ASSERT_TRUE(MakeTempFile(new_dir, sub_file, &full_path));
   full_path = base::MakeAbsoluteFilePath(full_path);
@@ -482,8 +501,8 @@ TEST(URLFixerTest, FixupRelativeFile) {
   // test file in the subdir
   base::FilePath relative_file = sub_dir.Append(sub_file);
   EXPECT_TRUE(IsMatchingFileURL(
-      url_fixer::FixupRelativeFile(dir, relative_file).possibly_invalid_spec(),
-      full_path));
+      url_fixer::FixupRelativeFile(temp_dir_.path(),
+          relative_file).possibly_invalid_spec(), full_path));
 
   // test file in the subdir with different slashes and escaping.
   base::FilePath::StringType relative_file_str = sub_dir.value() +
@@ -491,18 +510,18 @@ TEST(URLFixerTest, FixupRelativeFile) {
   ReplaceSubstringsAfterOffset(&relative_file_str, 0,
       FILE_PATH_LITERAL(" "), FILE_PATH_LITERAL("%20"));
   EXPECT_TRUE(IsMatchingFileURL(
-      url_fixer::FixupRelativeFile(dir, base::FilePath(relative_file_str))
-          .possibly_invalid_spec(),
-      full_path));
+      url_fixer::FixupRelativeFile(temp_dir_.path(),
+          base::FilePath(relative_file_str)).possibly_invalid_spec(),
+              full_path));
 
   // test relative directories and duplicate slashes
   // (should resolve to the same file as above)
   relative_file_str = sub_dir.value() + FILE_PATH_LITERAL("/../") +
       sub_dir.value() + FILE_PATH_LITERAL("///./") + sub_file.value();
   EXPECT_TRUE(IsMatchingFileURL(
-      url_fixer::FixupRelativeFile(dir, base::FilePath(relative_file_str))
-          .possibly_invalid_spec(),
-      full_path));
+      url_fixer::FixupRelativeFile(temp_dir_.path(),
+          base::FilePath(relative_file_str)).possibly_invalid_spec(),
+              full_path));
 
   // done with the subdir
   EXPECT_TRUE(base::DeleteFile(full_path, false));