Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/browser.h" | 5 #include "chrome/browser/browser.h" |
| 6 #include "chrome/browser/extensions/extension_host.h" | 6 #include "chrome/browser/extensions/extension_host.h" |
| 7 #include "chrome/browser/extensions/extension_shelf_model.h" | 7 #include "chrome/browser/extensions/extension_shelf_model.h" |
| 8 #include "chrome/browser/extensions/extensions_service.h" | 8 #include "chrome/browser/extensions/extensions_service.h" |
| 9 #include "chrome/browser/extensions/test_extension_loader.h" | 9 #include "chrome/browser/extensions/test_extension_loader.h" |
| 10 #include "chrome/browser/profile.h" | 10 #include "chrome/browser/profile.h" |
| 11 #include "chrome/common/chrome_paths.h" | 11 #include "chrome/common/chrome_paths.h" |
| 12 #include "chrome/common/chrome_switches.h" | 12 #include "chrome/common/chrome_switches.h" |
| 13 #include "chrome/common/extensions/extension_error_reporter.h" | 13 #include "chrome/common/extensions/extension_error_reporter.h" |
| 14 #include "chrome/test/in_process_browser_test.h" | 14 #include "chrome/test/in_process_browser_test.h" |
| 15 | 15 |
| 16 namespace { | 16 namespace { |
| 17 | 17 |
| 18 // The extension we're using as our test case. | 18 // The extension we're using as our test case. |
| 19 const char* kExtensionId = "fc6f6ba6693faf6773c13701019f2e7a12f0febe"; | 19 const char* kExtensionId = "behllobkkfkfnphdnhnkndlbkcpglgmj"; |
| 20 | 20 |
| 21 }; // namespace | 21 }; // namespace |
| 22 | 22 |
| 23 | 23 |
| 24 // An InProcessBrowserTest for testing the ExtensionShelfModel. | 24 // An InProcessBrowserTest for testing the ExtensionShelfModel. |
| 25 // TODO(erikkay) It's unfortunate that this needs to be an in-proc browser test. | 25 // TODO(erikkay) It's unfortunate that this needs to be an in-proc browser test. |
| 26 // It would be nice to refactor things so that ExtensionShelfModel, | 26 // It would be nice to refactor things so that ExtensionShelfModel, |
| 27 // ExtensionHost and ExtensionsService could run without so much of the browser | 27 // ExtensionHost and ExtensionsService could run without so much of the browser |
| 28 // in place. | 28 // in place. |
| 29 class ExtensionShelfModelTest : public InProcessBrowserTest, | 29 class ExtensionShelfModelTest : public InProcessBrowserTest, |
| 30 public ExtensionShelfModelObserver { | 30 public ExtensionShelfModelObserver { |
| 31 public: | 31 public: |
| 32 virtual void SetUp() { | 32 virtual void SetUp() { |
| 33 // Initialize the error reporter here, or BrowserMain will create it with | 33 // Initialize the error reporter here, or BrowserMain will create it with |
| 34 // the wrong MessageLoop. | 34 // the wrong MessageLoop. |
| 35 ExtensionErrorReporter::Init(false); | 35 ExtensionErrorReporter::Init(false); |
| 36 inserted_count_ = 0; | 36 inserted_count_ = 0; |
| 37 removed_count_ = 0; | 37 removed_count_ = 0; |
| 38 moved_count_ = 0; | 38 moved_count_ = 0; |
| 39 | 39 |
| 40 InProcessBrowserTest::SetUp(); | 40 InProcessBrowserTest::SetUp(); |
| 41 } | 41 } |
| 42 | 42 |
| 43 virtual void TearDown() { | |
| 44 // Tear down |model_| manually here rather than in the destructor or with | |
| 45 // a scoped_ptr. Since it uses NotificationRegistrar, it needs to clean up | |
| 46 // before the rest of InProcessBrowserTest. | |
| 47 model_->RemoveObserver(this); | |
| 48 delete model_; | |
| 49 model_ = NULL; | |
| 50 InProcessBrowserTest::TearDown(); | |
| 51 } | |
| 52 | |
| 53 virtual void SetUpCommandLine(CommandLine* command_line) { | 43 virtual void SetUpCommandLine(CommandLine* command_line) { |
| 54 command_line->AppendSwitch(switches::kEnableExtensions); | 44 command_line->AppendSwitch(switches::kEnableExtensions); |
| 55 } | 45 } |
| 56 | 46 |
| 57 virtual Browser* CreateBrowser(Profile* profile) { | 47 virtual Browser* CreateBrowser(Profile* profile) { |
| 58 Browser* b = InProcessBrowserTest::CreateBrowser(profile); | 48 Browser* b = InProcessBrowserTest::CreateBrowser(profile); |
| 59 model_ = new ExtensionShelfModel(b); | 49 model_ = new ExtensionShelfModel(b); |
| 60 model_->AddObserver(this); | 50 model_->AddObserver(this); |
| 61 return b; | 51 return b; |
| 62 } | 52 } |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 81 int inserted_count_; | 71 int inserted_count_; |
| 82 int removed_count_; | 72 int removed_count_; |
| 83 int moved_count_; | 73 int moved_count_; |
| 84 }; | 74 }; |
| 85 | 75 |
| 86 IN_PROC_BROWSER_TEST_F(ExtensionShelfModelTest, Basic) { | 76 IN_PROC_BROWSER_TEST_F(ExtensionShelfModelTest, Basic) { |
| 87 // Get the path to our extension. | 77 // Get the path to our extension. |
| 88 FilePath path; | 78 FilePath path; |
| 89 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &path)); | 79 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &path)); |
| 90 path = path.AppendASCII("extensions"). | 80 path = path.AppendASCII("extensions"). |
| 91 AppendASCII("good").AppendASCII("extension1").AppendASCII("1"); | 81 AppendASCII("good").AppendASCII(kExtensionId).AppendASCII("1.0.0.0"); |
| 92 ASSERT_TRUE(file_util::DirectoryExists(path)); // sanity check | 82 ASSERT_TRUE(file_util::DirectoryExists(path)); // sanity check |
| 93 | 83 |
| 94 // Wait for the extension to load and grab a pointer to it. | 84 // Wait for the extension to load and grab a pointer to it. |
| 95 TestExtensionLoader loader(browser()->profile()); | 85 TestExtensionLoader loader(browser()->profile()); |
| 96 Extension* extension = loader.Load(kExtensionId, path); | 86 Extension* extension = loader.Load(kExtensionId, path); |
| 97 ASSERT_TRUE(extension); | 87 ASSERT_TRUE(extension); |
| 98 | 88 |
| 99 // extension1 has two toolstrips | 89 // extension1 has two toolstrips |
| 100 EXPECT_EQ(inserted_count_, 2); | 90 EXPECT_EQ(inserted_count_, 2); |
| 101 ExtensionHost* one = model_->ToolstripAt(0); | 91 ExtensionHost* one = model_->ToolstripAt(0); |
| 102 ExtensionHost* two = model_->ToolstripAt(1); | 92 ExtensionHost* two = model_->ToolstripAt(1); |
| 103 EXPECT_EQ(one->GetURL().path(), "/toolstrip1.html"); | 93 EXPECT_EQ(one->GetURL().path(), "/toolstrip1.html"); |
| 104 EXPECT_EQ(two->GetURL().path(), "/toolstrip2.html"); | 94 EXPECT_EQ(two->GetURL().path(), "/toolstrip2.html"); |
| 105 | 95 |
| 106 model_->MoveToolstripAt(0, 1); | 96 model_->MoveToolstripAt(0, 1); |
| 107 EXPECT_EQ(two, model_->ToolstripAt(0)); | 97 EXPECT_EQ(two, model_->ToolstripAt(0)); |
| 108 EXPECT_EQ(one, model_->ToolstripAt(1)); | 98 EXPECT_EQ(one, model_->ToolstripAt(1)); |
| 109 EXPECT_EQ(moved_count_, 1); | 99 EXPECT_EQ(moved_count_, 1); |
| 110 | 100 |
| 111 model_->RemoveToolstripAt(0); | 101 model_->RemoveToolstripAt(0); |
| 112 EXPECT_EQ(one, model_->ToolstripAt(0)); | 102 EXPECT_EQ(one, model_->ToolstripAt(0)); |
| 113 EXPECT_EQ(1, model_->count()); | 103 EXPECT_EQ(1, model_->count()); |
| 114 EXPECT_EQ(removed_count_, 1); | 104 EXPECT_EQ(removed_count_, 1); |
| 105 | |
| 106 // Tear down |model_| manually here rather than in the destructor or with | |
| 107 // a scoped_ptr. Since it uses NotificationRegistrar, it needs to clean up | |
| 108 // before the rest of InProcessBrowserTest. | |
|
Matt Perry
2009/06/23 23:05:35
update comment to explain why this isn't in TearDo
| |
| 109 model_->RemoveObserver(this); | |
| 110 delete model_; | |
| 111 model_ = NULL; | |
| 115 } | 112 } |
| OLD | NEW |