| OLD | NEW |
| 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 "chrome/browser/chromeos/extensions/default_app_order.h" | 5 #include "chrome/browser/chromeos/extensions/default_app_order.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <memory> |
| 9 #include <string> | 10 #include <string> |
| 10 #include <vector> | 11 #include <vector> |
| 11 | 12 |
| 12 #include "base/files/file_path.h" | 13 #include "base/files/file_path.h" |
| 13 #include "base/files/file_util.h" | 14 #include "base/files/file_util.h" |
| 14 #include "base/files/scoped_temp_dir.h" | 15 #include "base/files/scoped_temp_dir.h" |
| 15 #include "base/macros.h" | 16 #include "base/macros.h" |
| 16 #include "base/memory/scoped_ptr.h" | |
| 17 #include "base/test/scoped_path_override.h" | 17 #include "base/test/scoped_path_override.h" |
| 18 #include "chrome/common/extensions/extension_constants.h" | 18 #include "chrome/common/extensions/extension_constants.h" |
| 19 #include "chromeos/chromeos_paths.h" | 19 #include "chromeos/chromeos_paths.h" |
| 20 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
| 21 | 21 |
| 22 namespace chromeos { | 22 namespace chromeos { |
| 23 | 23 |
| 24 namespace { | 24 namespace { |
| 25 | 25 |
| 26 const base::FilePath::CharType kTestFile[] = | 26 const base::FilePath::CharType kTestFile[] = |
| (...skipping 30 matching lines...) Expand all Loading... |
| 57 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 57 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
| 58 base::FilePath external_file = temp_dir_.path().Append(kTestFile); | 58 base::FilePath external_file = temp_dir_.path().Append(kTestFile); |
| 59 base::WriteFile(external_file, content.c_str(), content.size()); | 59 base::WriteFile(external_file, content.c_str(), content.size()); |
| 60 SetExternalFile(external_file); | 60 SetExternalFile(external_file); |
| 61 } | 61 } |
| 62 | 62 |
| 63 private: | 63 private: |
| 64 std::vector<std::string> built_in_default_; | 64 std::vector<std::string> built_in_default_; |
| 65 | 65 |
| 66 base::ScopedTempDir temp_dir_; | 66 base::ScopedTempDir temp_dir_; |
| 67 scoped_ptr<base::ScopedPathOverride> path_override_; | 67 std::unique_ptr<base::ScopedPathOverride> path_override_; |
| 68 | 68 |
| 69 DISALLOW_COPY_AND_ASSIGN(DefaultAppOrderTest); | 69 DISALLOW_COPY_AND_ASSIGN(DefaultAppOrderTest); |
| 70 }; | 70 }; |
| 71 | 71 |
| 72 // Tests that the built-in default order is returned when ExternalLoader is not | 72 // Tests that the built-in default order is returned when ExternalLoader is not |
| 73 // created. | 73 // created. |
| 74 TEST_F(DefaultAppOrderTest, BuiltInDefault) { | 74 TEST_F(DefaultAppOrderTest, BuiltInDefault) { |
| 75 std::vector<std::string> apps; | 75 std::vector<std::string> apps; |
| 76 default_app_order::Get(&apps); | 76 default_app_order::Get(&apps); |
| 77 EXPECT_TRUE(IsBuiltInDefault(apps)); | 77 EXPECT_TRUE(IsBuiltInDefault(apps)); |
| 78 } | 78 } |
| 79 | 79 |
| 80 // Tests external order file overrides built-in default. | 80 // Tests external order file overrides built-in default. |
| 81 TEST_F(DefaultAppOrderTest, ExternalOrder) { | 81 TEST_F(DefaultAppOrderTest, ExternalOrder) { |
| 82 const char kExternalOrder[] = "[\"app1\",\"app2\",\"app3\"," | 82 const char kExternalOrder[] = "[\"app1\",\"app2\",\"app3\"," |
| 83 "{ \"oem_apps_folder\": true,\"localized_content\": {" | 83 "{ \"oem_apps_folder\": true,\"localized_content\": {" |
| 84 " \"default\": {\"name\": \"OEM name\"}}}]"; | 84 " \"default\": {\"name\": \"OEM name\"}}}]"; |
| 85 CreateExternalOrderFile(std::string(kExternalOrder)); | 85 CreateExternalOrderFile(std::string(kExternalOrder)); |
| 86 | 86 |
| 87 scoped_ptr<default_app_order::ExternalLoader> loader( | 87 std::unique_ptr<default_app_order::ExternalLoader> loader( |
| 88 new default_app_order::ExternalLoader(false)); | 88 new default_app_order::ExternalLoader(false)); |
| 89 | 89 |
| 90 std::vector<std::string> apps; | 90 std::vector<std::string> apps; |
| 91 default_app_order::Get(&apps); | 91 default_app_order::Get(&apps); |
| 92 EXPECT_EQ(3u, apps.size()); | 92 EXPECT_EQ(3u, apps.size()); |
| 93 EXPECT_EQ(std::string("app1"), apps[0]); | 93 EXPECT_EQ(std::string("app1"), apps[0]); |
| 94 EXPECT_EQ(std::string("app2"), apps[1]); | 94 EXPECT_EQ(std::string("app2"), apps[1]); |
| 95 EXPECT_EQ(std::string("app3"), apps[2]); | 95 EXPECT_EQ(std::string("app3"), apps[2]); |
| 96 EXPECT_EQ(std::string("OEM name"), default_app_order::GetOemAppsFolderName()); | 96 EXPECT_EQ(std::string("OEM name"), default_app_order::GetOemAppsFolderName()); |
| 97 } | 97 } |
| 98 | 98 |
| 99 // Tests none-existent order file gives built-in default. | 99 // Tests none-existent order file gives built-in default. |
| 100 TEST_F(DefaultAppOrderTest, NoExternalFile) { | 100 TEST_F(DefaultAppOrderTest, NoExternalFile) { |
| 101 base::ScopedTempDir scoped_tmp_dir; | 101 base::ScopedTempDir scoped_tmp_dir; |
| 102 ASSERT_TRUE(scoped_tmp_dir.CreateUniqueTempDir()); | 102 ASSERT_TRUE(scoped_tmp_dir.CreateUniqueTempDir()); |
| 103 | 103 |
| 104 base::FilePath none_existent_file = | 104 base::FilePath none_existent_file = |
| 105 scoped_tmp_dir.path().AppendASCII("none_existent_file"); | 105 scoped_tmp_dir.path().AppendASCII("none_existent_file"); |
| 106 ASSERT_FALSE(base::PathExists(none_existent_file)); | 106 ASSERT_FALSE(base::PathExists(none_existent_file)); |
| 107 SetExternalFile(none_existent_file); | 107 SetExternalFile(none_existent_file); |
| 108 | 108 |
| 109 scoped_ptr<default_app_order::ExternalLoader> loader( | 109 std::unique_ptr<default_app_order::ExternalLoader> loader( |
| 110 new default_app_order::ExternalLoader(false)); | 110 new default_app_order::ExternalLoader(false)); |
| 111 | 111 |
| 112 std::vector<std::string> apps; | 112 std::vector<std::string> apps; |
| 113 default_app_order::Get(&apps); | 113 default_app_order::Get(&apps); |
| 114 EXPECT_TRUE(IsBuiltInDefault(apps)); | 114 EXPECT_TRUE(IsBuiltInDefault(apps)); |
| 115 } | 115 } |
| 116 | 116 |
| 117 // Tests bad json file gives built-in default. | 117 // Tests bad json file gives built-in default. |
| 118 TEST_F(DefaultAppOrderTest, BadExternalFile) { | 118 TEST_F(DefaultAppOrderTest, BadExternalFile) { |
| 119 const char kExternalOrder[] = "This is not a valid json."; | 119 const char kExternalOrder[] = "This is not a valid json."; |
| 120 CreateExternalOrderFile(std::string(kExternalOrder)); | 120 CreateExternalOrderFile(std::string(kExternalOrder)); |
| 121 | 121 |
| 122 scoped_ptr<default_app_order::ExternalLoader> loader( | 122 std::unique_ptr<default_app_order::ExternalLoader> loader( |
| 123 new default_app_order::ExternalLoader(false)); | 123 new default_app_order::ExternalLoader(false)); |
| 124 | 124 |
| 125 std::vector<std::string> apps; | 125 std::vector<std::string> apps; |
| 126 default_app_order::Get(&apps); | 126 default_app_order::Get(&apps); |
| 127 EXPECT_TRUE(IsBuiltInDefault(apps)); | 127 EXPECT_TRUE(IsBuiltInDefault(apps)); |
| 128 } | 128 } |
| 129 | 129 |
| 130 TEST_F(DefaultAppOrderTest, ImportDefault) { | 130 TEST_F(DefaultAppOrderTest, ImportDefault) { |
| 131 const char kExternalOrder[] = | 131 const char kExternalOrder[] = |
| 132 "[\"app1\"," | 132 "[\"app1\"," |
| 133 "{ \"import_default_order\": true }, \"app2\"]"; | 133 "{ \"import_default_order\": true }, \"app2\"]"; |
| 134 CreateExternalOrderFile(std::string(kExternalOrder)); | 134 CreateExternalOrderFile(std::string(kExternalOrder)); |
| 135 | 135 |
| 136 scoped_ptr<default_app_order::ExternalLoader> loader( | 136 std::unique_ptr<default_app_order::ExternalLoader> loader( |
| 137 new default_app_order::ExternalLoader(false)); | 137 new default_app_order::ExternalLoader(false)); |
| 138 | 138 |
| 139 std::vector<std::string> apps; | 139 std::vector<std::string> apps; |
| 140 default_app_order::Get(&apps); | 140 default_app_order::Get(&apps); |
| 141 EXPECT_EQ(default_app_order::kDefaultAppOrderCount + 2, apps.size()); | 141 EXPECT_EQ(default_app_order::kDefaultAppOrderCount + 2, apps.size()); |
| 142 EXPECT_EQ(std::string("app1"), apps[0]); | 142 EXPECT_EQ(std::string("app1"), apps[0]); |
| 143 EXPECT_EQ(extension_misc::kChromeAppId, apps[1]); | 143 EXPECT_EQ(extension_misc::kChromeAppId, apps[1]); |
| 144 EXPECT_EQ(std::string("app2"), | 144 EXPECT_EQ(std::string("app2"), |
| 145 apps[default_app_order::kDefaultAppOrderCount + 1]); | 145 apps[default_app_order::kDefaultAppOrderCount + 1]); |
| 146 } | 146 } |
| 147 | 147 |
| 148 } // namespace chromeos | 148 } // namespace chromeos |
| OLD | NEW |