| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/browser.h" | |
| 6 #include "chrome/browser/extensions/extension_browsertest.h" | |
| 7 #include "chrome/browser/extensions/extension_error_reporter.h" | |
| 8 #include "chrome/browser/extensions/extension_host.h" | |
| 9 #include "chrome/browser/extensions/extension_shelf_model.h" | |
| 10 #include "chrome/browser/extensions/extensions_service.h" | |
| 11 #include "chrome/browser/profile.h" | |
| 12 #include "chrome/browser/views/extensions/extension_shelf.h" | |
| 13 #include "chrome/browser/views/frame/browser_view.h" | |
| 14 #include "chrome/common/chrome_paths.h" | |
| 15 #include "chrome/common/chrome_switches.h" | |
| 16 #include "chrome/test/in_process_browser_test.h" | |
| 17 | |
| 18 namespace { | |
| 19 | |
| 20 // The extension we're using as our test case. | |
| 21 const char* kExtensionId = "behllobkkfkfnphdnhnkndlbkcpglgmj"; | |
| 22 | |
| 23 }; // namespace | |
| 24 | |
| 25 | |
| 26 // An InProcessBrowserTest for testing the ExtensionShelfModel. | |
| 27 // TODO(erikkay) It's unfortunate that this needs to be an in-proc browser test. | |
| 28 // It would be nice to refactor things so that ExtensionShelfModel, | |
| 29 // ExtensionHost and ExtensionsService could run without so much of the browser | |
| 30 // in place. | |
| 31 class ExtensionShelfModelTest : public ExtensionBrowserTest, | |
| 32 public ExtensionShelfModelObserver { | |
| 33 public: | |
| 34 virtual void SetUp() { | |
| 35 inserted_count_ = 0; | |
| 36 removed_count_ = 0; | |
| 37 moved_count_ = 0; | |
| 38 InProcessBrowserTest::SetUp(); | |
| 39 } | |
| 40 | |
| 41 virtual Browser* CreateBrowser(Profile* profile) { | |
| 42 Browser* b = InProcessBrowserTest::CreateBrowser(profile); | |
| 43 BrowserView* browser_view = static_cast<BrowserView*>(b->window()); | |
| 44 model_ = browser_view->extension_shelf()->model(); | |
| 45 model_->AddObserver(this); | |
| 46 return b; | |
| 47 } | |
| 48 | |
| 49 virtual void CleanUpOnMainThread() { | |
| 50 model_->RemoveObserver(this); | |
| 51 } | |
| 52 | |
| 53 virtual void ToolstripInsertedAt(ExtensionHost* toolstrip, int index) { | |
| 54 inserted_count_++; | |
| 55 } | |
| 56 | |
| 57 virtual void ToolstripRemovingAt(ExtensionHost* toolstrip, int index) { | |
| 58 removed_count_++; | |
| 59 } | |
| 60 | |
| 61 virtual void ToolstripMoved(ExtensionHost* toolstrip, | |
| 62 int from_index, | |
| 63 int to_index) { | |
| 64 moved_count_++; | |
| 65 } | |
| 66 | |
| 67 protected: | |
| 68 ExtensionShelfModel* model_; | |
| 69 | |
| 70 int inserted_count_; | |
| 71 int removed_count_; | |
| 72 int moved_count_; | |
| 73 }; | |
| 74 | |
| 75 IN_PROC_BROWSER_TEST_F(ExtensionShelfModelTest, Basic) { | |
| 76 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("good") | |
| 77 .AppendASCII("Extensions") | |
| 78 .AppendASCII(kExtensionId) | |
| 79 .AppendASCII("1.0.0.0"))); | |
| 80 | |
| 81 // extension1 has two toolstrips | |
| 82 EXPECT_EQ(inserted_count_, 2); | |
| 83 ExtensionHost* one = model_->ToolstripAt(0).host; | |
| 84 ExtensionHost* two = model_->ToolstripAt(1).host; | |
| 85 EXPECT_EQ(one->GetURL().path(), "/toolstrip1.html"); | |
| 86 EXPECT_EQ(two->GetURL().path(), "/toolstrip2.html"); | |
| 87 | |
| 88 model_->MoveToolstripAt(0, 1); | |
| 89 EXPECT_EQ(two, model_->ToolstripAt(0).host); | |
| 90 EXPECT_EQ(one, model_->ToolstripAt(1).host); | |
| 91 EXPECT_EQ(moved_count_, 1); | |
| 92 | |
| 93 model_->RemoveToolstripAt(0); | |
| 94 EXPECT_EQ(one, model_->ToolstripAt(0).host); | |
| 95 EXPECT_EQ(1, model_->count()); | |
| 96 EXPECT_EQ(removed_count_, 1); | |
| 97 } | |
| OLD | NEW |