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

Side by Side Diff: extensions/browser/api/api_resource_manager_unittest.cc

Issue 431023003: Remove deprecated extension notifications from ApiResourceManager (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 4 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 | « extensions/browser/api/api_resource_manager.h ('k') | extensions/extensions.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/files/file_path.h" 5 #include "base/files/file_path.h"
6 #include "base/strings/string_util.h" 6 #include "base/strings/string_util.h"
7 #include "chrome/browser/extensions/extension_function_test_utils.h"
8 #include "content/public/browser/browser_thread.h" 7 #include "content/public/browser/browser_thread.h"
9 #include "content/public/test/test_browser_thread_bundle.h" 8 #include "content/public/test/test_browser_thread_bundle.h"
10 #include "extensions/browser/api/api_resource.h" 9 #include "extensions/browser/api/api_resource.h"
11 #include "extensions/browser/api/api_resource_manager.h" 10 #include "extensions/browser/api/api_resource_manager.h"
11 #include "extensions/browser/extensions_test.h"
12 #include "extensions/common/extension.h" 12 #include "extensions/common/extension.h"
13 #include "extensions/common/id_util.h"
14 #include "extensions/common/test_util.h"
13 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
14 #include "url/gurl.h" 16 #include "url/gurl.h"
15 17
16 namespace utils = extension_function_test_utils;
17
18 using content::BrowserThread; 18 using content::BrowserThread;
19 using content::NotificationService;
19 20
20 namespace extensions { 21 namespace extensions {
21 22
22 class ApiResourceManagerUnitTest : public testing::Test { 23 class ApiResourceManagerUnitTest : public ExtensionsTest {
24 public:
25 ApiResourceManagerUnitTest()
26 : notification_service_(NotificationService::Create()) {}
27
23 private: 28 private:
24 content::TestBrowserThreadBundle thread_bundle_; 29 content::TestBrowserThreadBundle thread_bundle_;
30 scoped_ptr<NotificationService> notification_service_;
25 }; 31 };
26 32
27 class FakeApiResource : public ApiResource { 33 class FakeApiResource : public ApiResource {
28 public: 34 public:
29 explicit FakeApiResource(const std::string& owner_extension_id) 35 explicit FakeApiResource(const std::string& owner_extension_id)
30 : ApiResource(owner_extension_id) {} 36 : ApiResource(owner_extension_id) {}
31 virtual ~FakeApiResource() {} 37 virtual ~FakeApiResource() {}
32 static const BrowserThread::ID kThreadId = BrowserThread::UI; 38 static const BrowserThread::ID kThreadId = BrowserThread::UI;
33 }; 39 };
34 40
35 TEST_F(ApiResourceManagerUnitTest, TwoAppsCannotShareResources) { 41 TEST_F(ApiResourceManagerUnitTest, TwoAppsCannotShareResources) {
36 scoped_ptr<ApiResourceManager<FakeApiResource> > manager( 42 scoped_ptr<ApiResourceManager<FakeApiResource> > manager(
37 new ApiResourceManager<FakeApiResource>(NULL)); 43 new ApiResourceManager<FakeApiResource>(NULL));
38 scoped_refptr<extensions::Extension> extension_one( 44 scoped_refptr<extensions::Extension> extension_one =
39 utils::CreateEmptyExtension("one")); 45 test_util::CreateExtensionWithID("one");
40 scoped_refptr<extensions::Extension> extension_two( 46 scoped_refptr<extensions::Extension> extension_two =
41 utils::CreateEmptyExtension("two")); 47 test_util::CreateExtensionWithID("two");
42 48
43 const std::string extension_one_id(extension_one->id()); 49 const std::string extension_one_id(extension_one->id());
44 const std::string extension_two_id(extension_two->id()); 50 const std::string extension_two_id(extension_two->id());
45 51
46 int resource_one_id = manager->Add(new FakeApiResource(extension_one_id)); 52 int resource_one_id = manager->Add(new FakeApiResource(extension_one_id));
47 int resource_two_id = manager->Add(new FakeApiResource(extension_two_id)); 53 int resource_two_id = manager->Add(new FakeApiResource(extension_two_id));
48 CHECK(resource_one_id); 54 CHECK(resource_one_id);
49 CHECK(resource_two_id); 55 CHECK(resource_two_id);
50 56
51 // Confirm each extension can get its own resource. 57 // Confirm each extension can get its own resource.
52 ASSERT_TRUE(manager->Get(extension_one_id, resource_one_id) != NULL); 58 ASSERT_TRUE(manager->Get(extension_one_id, resource_one_id) != NULL);
53 ASSERT_TRUE(manager->Get(extension_two_id, resource_two_id) != NULL); 59 ASSERT_TRUE(manager->Get(extension_two_id, resource_two_id) != NULL);
54 60
55 // Confirm neither extension can get the other's resource. 61 // Confirm neither extension can get the other's resource.
56 ASSERT_TRUE(manager->Get(extension_one_id, resource_two_id) == NULL); 62 ASSERT_TRUE(manager->Get(extension_one_id, resource_two_id) == NULL);
57 ASSERT_TRUE(manager->Get(extension_two_id, resource_one_id) == NULL); 63 ASSERT_TRUE(manager->Get(extension_two_id, resource_one_id) == NULL);
58 64
59 // And make sure we're not susceptible to any Jedi mind tricks. 65 // And make sure we're not susceptible to any Jedi mind tricks.
60 ASSERT_TRUE(manager->Get(std::string(), resource_one_id) == NULL); 66 ASSERT_TRUE(manager->Get(std::string(), resource_one_id) == NULL);
61 } 67 }
62 68
63 } // namespace extensions 69 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/browser/api/api_resource_manager.h ('k') | extensions/extensions.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698