OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 <algorithm> | 5 #include <algorithm> |
6 #include <vector> | 6 #include <vector> |
7 | 7 |
8 #include "base/file_path.h" | 8 #include "base/file_path.h" |
9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 std::vector<std::string> errors_; | 71 std::vector<std::string> errors_; |
72 }; | 72 }; |
73 | 73 |
74 // make the test a PlatformTest to setup autorelease pools properly on mac | 74 // make the test a PlatformTest to setup autorelease pools properly on mac |
75 typedef PlatformTest ExtensionsServiceTest; | 75 typedef PlatformTest ExtensionsServiceTest; |
76 | 76 |
77 // Test loading extensions from the profile directory. | 77 // Test loading extensions from the profile directory. |
78 TEST_F(ExtensionsServiceTest, LoadAllExtensionsFromDirectory) { | 78 TEST_F(ExtensionsServiceTest, LoadAllExtensionsFromDirectory) { |
79 std::wstring extensions_dir; | 79 std::wstring extensions_dir; |
80 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_dir)); | 80 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_dir)); |
81 FilePath manifest_path = FilePath::FromWStringHack(extensions_dir).Append( | 81 FilePath extensions_path = FilePath::FromWStringHack(extensions_dir).Append( |
82 FILE_PATH_LITERAL("extensions")); | 82 FILE_PATH_LITERAL("extensions")); |
83 | 83 |
84 scoped_refptr<ExtensionsServiceBackend> backend(new ExtensionsServiceBackend); | 84 scoped_refptr<ExtensionsServiceBackend> backend(new ExtensionsServiceBackend); |
85 scoped_refptr<ExtensionsServiceTestFrontend> frontend( | 85 scoped_refptr<ExtensionsServiceTestFrontend> frontend( |
86 new ExtensionsServiceTestFrontend); | 86 new ExtensionsServiceTestFrontend); |
87 | 87 |
88 std::vector<Extension*> extensions; | 88 std::vector<Extension*> extensions; |
89 EXPECT_TRUE(backend->LoadExtensionsFromDirectory(manifest_path, | 89 EXPECT_TRUE(backend->LoadExtensionsFromDirectory(extensions_path, |
90 scoped_refptr<ExtensionsServiceFrontendInterface>(frontend.get()))); | 90 scoped_refptr<ExtensionsServiceFrontendInterface>(frontend.get()))); |
91 frontend->GetMessageLoop()->RunAllPending(); | 91 frontend->GetMessageLoop()->RunAllPending(); |
92 | 92 |
93 // Note: There can be more errors if there are extra directories, like .svn | 93 // Note: There can be more errors if there are extra directories, like .svn |
94 // directories. | 94 // directories. |
95 EXPECT_TRUE(frontend->errors()->size() >= 2u); | 95 EXPECT_TRUE(frontend->errors()->size() >= 2u); |
96 ASSERT_EQ(2u, frontend->extensions()->size()); | 96 ASSERT_EQ(2u, frontend->extensions()->size()); |
97 | 97 |
98 EXPECT_EQ(std::string("com.google.myextension1"), | 98 EXPECT_EQ(std::string("com.google.myextension1"), |
99 frontend->extensions()->at(0)->id()); | 99 frontend->extensions()->at(0)->id()); |
100 EXPECT_EQ(std::string("My extension 1"), | 100 EXPECT_EQ(std::string("My extension 1"), |
101 frontend->extensions()->at(0)->name()); | 101 frontend->extensions()->at(0)->name()); |
102 EXPECT_EQ(std::string("The first extension that I made."), | 102 EXPECT_EQ(std::string("The first extension that I made."), |
103 frontend->extensions()->at(0)->description()); | 103 frontend->extensions()->at(0)->description()); |
104 ASSERT_EQ(2u, frontend->extensions()->at(0)->content_scripts().size()); | 104 |
105 EXPECT_EQ(std::string("script1.user.js"), | 105 Extension* extension = frontend->extensions()->at(0); |
106 frontend->extensions()->at(0)->content_scripts().at(0)); | 106 const UserScriptList& scripts = extension->user_scripts(); |
107 EXPECT_EQ(std::string("script2.user.js"), | 107 ASSERT_EQ(2u, scripts.size()); |
108 frontend->extensions()->at(0)->content_scripts().at(1)); | 108 EXPECT_EQ(2u, scripts[0].matches.size()); |
| 109 EXPECT_EQ("http://*.google.com/*", scripts[0].matches[0]); |
| 110 EXPECT_EQ("https://*.google.com/*", scripts[0].matches[1]); |
| 111 EXPECT_EQ(extension->path().Append(FILE_PATH_LITERAL("script1.js")).value(), |
| 112 scripts[0].path.value()); |
| 113 EXPECT_EQ(1u, scripts[1].matches.size()); |
| 114 EXPECT_EQ("http://*.yahoo.com/*", scripts[1].matches[0]); |
| 115 EXPECT_EQ(extension->path().Append(FILE_PATH_LITERAL("script2.js")).value(), |
| 116 scripts[1].path.value()); |
109 | 117 |
110 EXPECT_EQ(std::string("com.google.myextension2"), | 118 EXPECT_EQ(std::string("com.google.myextension2"), |
111 frontend->extensions()->at(1)->id()); | 119 frontend->extensions()->at(1)->id()); |
112 EXPECT_EQ(std::string("My extension 2"), | 120 EXPECT_EQ(std::string("My extension 2"), |
113 frontend->extensions()->at(1)->name()); | 121 frontend->extensions()->at(1)->name()); |
114 EXPECT_EQ(std::string(""), | 122 EXPECT_EQ(std::string(""), |
115 frontend->extensions()->at(1)->description()); | 123 frontend->extensions()->at(1)->description()); |
116 ASSERT_EQ(0u, frontend->extensions()->at(1)->content_scripts().size()); | 124 ASSERT_EQ(0u, frontend->extensions()->at(1)->user_scripts().size()); |
117 }; | 125 }; |
OLD | NEW |