| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "ui/aura_shell/launcher/launcher_model.h" | 5 #include "ui/aura_shell/launcher/launcher_model.h" |
| 6 | 6 |
| 7 #include "base/stringprintf.h" | 7 #include "base/stringprintf.h" |
| 8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
| 9 #include "ui/aura_shell/launcher/launcher_model_observer.h" | 9 #include "ui/aura_shell/launcher/launcher_model_observer.h" |
| 10 #include "views/view.h" | |
| 11 | |
| 12 using views::View; | |
| 13 | 10 |
| 14 namespace aura_shell { | 11 namespace aura_shell { |
| 15 | 12 |
| 16 namespace { | 13 namespace { |
| 17 | 14 |
| 18 // LauncherModelObserver implementation that tracks what message are invoked. | 15 // LauncherModelObserver implementation that tracks what message are invoked. |
| 19 class TestLauncherModelObserver : public LauncherModelObserver { | 16 class TestLauncherModelObserver : public LauncherModelObserver { |
| 20 public: | 17 public: |
| 21 TestLauncherModelObserver() | 18 TestLauncherModelObserver() |
| 22 : added_count_(0), | 19 : added_count_(0), |
| 23 removed_count_(0), | 20 removed_count_(0), |
| 24 selection_changed_count_(0) { | 21 images_changed_count_(0) { |
| 25 } | 22 } |
| 26 | 23 |
| 27 // Returns a string description of the changes that have occurred since this | 24 // Returns a string description of the changes that have occurred since this |
| 28 // was last invoked. Resets state to initial state. | 25 // was last invoked. Resets state to initial state. |
| 29 std::string StateStringAndClear() { | 26 std::string StateStringAndClear() { |
| 30 std::string result(base::StringPrintf("added=%d removed=%d s_changed=%d", | 27 std::string result( |
| 31 added_count_, removed_count_, selection_changed_count_)); | 28 base::StringPrintf("added=%d removed=%d images_changed=%d", |
| 32 added_count_ = removed_count_ = selection_changed_count_ = 0; | 29 added_count_, removed_count_, images_changed_count_)); |
| 30 added_count_ = removed_count_ = images_changed_count_ = 0; |
| 33 return result; | 31 return result; |
| 34 } | 32 } |
| 35 | 33 |
| 36 // LauncherModelObserver overrides: | 34 // LauncherModelObserver overrides: |
| 37 virtual void LauncherItemAdded(int index) OVERRIDE { | 35 virtual void LauncherItemAdded(int index) OVERRIDE { |
| 38 added_count_++; | 36 added_count_++; |
| 39 } | 37 } |
| 40 virtual void LauncherItemRemoved(int index) OVERRIDE { | 38 virtual void LauncherItemRemoved(int index) OVERRIDE { |
| 41 removed_count_++; | 39 removed_count_++; |
| 42 } | 40 } |
| 43 virtual void LauncherSelectionChanged() OVERRIDE { | 41 virtual void LauncherItemImagesChanged(int index) OVERRIDE { |
| 44 selection_changed_count_++; | 42 images_changed_count_++; |
| 45 } | 43 } |
| 46 | 44 |
| 47 private: | 45 private: |
| 48 int added_count_; | 46 int added_count_; |
| 49 int removed_count_; | 47 int removed_count_; |
| 50 int selection_changed_count_; | 48 int images_changed_count_; |
| 51 | 49 |
| 52 DISALLOW_COPY_AND_ASSIGN(TestLauncherModelObserver); | 50 DISALLOW_COPY_AND_ASSIGN(TestLauncherModelObserver); |
| 53 }; | 51 }; |
| 54 | 52 |
| 55 } // namespace | 53 } // namespace |
| 56 | 54 |
| 57 TEST(TestLauncher, BasicAssertions) { | 55 TEST(TestLauncher, BasicAssertions) { |
| 58 TestLauncherModelObserver observer; | 56 TestLauncherModelObserver observer; |
| 59 LauncherModel model; | 57 LauncherModel model; |
| 60 // Add an item. | 58 // Add an item. |
| 61 model.AddObserver(&observer); | 59 model.AddObserver(&observer); |
| 62 EXPECT_EQ(-1, model.selected_index()); | 60 LauncherItem item; |
| 63 View* view = new View; | 61 model.Add(0, item); |
| 64 model.AddItem(view, 0, true); | |
| 65 EXPECT_EQ(1, model.item_count()); | 62 EXPECT_EQ(1, model.item_count()); |
| 66 EXPECT_EQ(view, model.view_at(0)); | 63 EXPECT_EQ("added=1 removed=0 images_changed=0", |
| 67 EXPECT_EQ(true, model.is_draggable(0)); | 64 observer.StateStringAndClear()); |
| 68 EXPECT_EQ(-1, model.selected_index()); | |
| 69 EXPECT_EQ("added=1 removed=0 s_changed=0", observer.StateStringAndClear()); | |
| 70 | 65 |
| 71 EXPECT_EQ(0, model.IndexOfItemByView(view)); | 66 // Change a tabbed image. |
| 72 EXPECT_EQ(-1, model.IndexOfItemByView(NULL)); | 67 model.SetTabbedImages(0, LauncherTabbedImages()); |
| 73 | 68 EXPECT_EQ("added=0 removed=0 images_changed=1", |
| 74 // Change the selection. | 69 observer.StateStringAndClear()); |
| 75 model.SetSelectedIndex(0); | |
| 76 EXPECT_EQ("added=0 removed=0 s_changed=1", observer.StateStringAndClear()); | |
| 77 | 70 |
| 78 // Remove the item. | 71 // Remove the item. |
| 79 model.RemoveItemAt(0); | 72 model.RemoveItemAt(0); |
| 80 delete view; // We now own the view. | |
| 81 view = NULL; | |
| 82 EXPECT_EQ(0, model.item_count()); | 73 EXPECT_EQ(0, model.item_count()); |
| 83 EXPECT_EQ(0, model.selected_index()); | 74 EXPECT_EQ("added=0 removed=1 images_changed=0", |
| 84 EXPECT_EQ("added=0 removed=1 s_changed=0", observer.StateStringAndClear()); | 75 observer.StateStringAndClear()); |
| 76 |
| 77 // Add an app item. |
| 78 item.type = TYPE_APP; |
| 79 model.Add(0, item); |
| 80 observer.StateStringAndClear(); |
| 81 |
| 82 // Change an app image. |
| 83 model.SetAppImage(0, SkBitmap()); |
| 84 EXPECT_EQ("added=0 removed=0 images_changed=1", |
| 85 observer.StateStringAndClear()); |
| 85 } | 86 } |
| 86 | 87 |
| 87 } // namespace aura_shell | 88 } // namespace aura_shell |
| OLD | NEW |