| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/status_icons/status_icon_menu_model.h" | 5 #include "chrome/browser/status_icons/status_icon_menu_model.h" |
| 6 | 6 |
| 7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
| 8 #include "base/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "chrome/browser/status_icons/status_icon.h" | 10 #include "chrome/browser/status_icons/status_icon.h" |
| 11 #include "chrome/browser/status_icons/status_tray.h" | 11 #include "chrome/browser/status_icons/status_tray.h" |
| 12 #include "grit/chrome_unscaled_resources.h" | |
| 13 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
| 14 #include "ui/base/accelerators/accelerator.h" | 13 #include "ui/base/accelerators/accelerator.h" |
| 15 #include "ui/base/resource/resource_bundle.h" | |
| 16 #include "ui/gfx/image/image.h" | 14 #include "ui/gfx/image/image.h" |
| 15 #include "ui/gfx/image/image_unittest_util.h" |
| 17 | 16 |
| 18 using base::ASCIIToUTF16; | 17 using base::ASCIIToUTF16; |
| 19 | 18 |
| 20 class StatusIconMenuModelTest : public testing::Test, | 19 class StatusIconMenuModelTest : public testing::Test, |
| 21 public StatusIconMenuModel::Observer { | 20 public StatusIconMenuModel::Observer { |
| 22 public: | 21 public: |
| 23 void SetUp() override { | 22 void SetUp() override { |
| 24 menu_.reset(new StatusIconMenuModel(NULL)); | 23 menu_.reset(new StatusIconMenuModel(NULL)); |
| 25 menu_->AddObserver(this); | 24 menu_->AddObserver(this); |
| 26 changed_count_ = 0; | 25 changed_count_ = 0; |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 | 62 |
| 64 // Menu state should have changed 7 times in this test. | 63 // Menu state should have changed 7 times in this test. |
| 65 EXPECT_EQ(7, changed_count()); | 64 EXPECT_EQ(7, changed_count()); |
| 66 } | 65 } |
| 67 | 66 |
| 68 TEST_F(StatusIconMenuModelTest, SetProperties) { | 67 TEST_F(StatusIconMenuModelTest, SetProperties) { |
| 69 menu_model()->AddItem(0, ASCIIToUTF16("foo1")); | 68 menu_model()->AddItem(0, ASCIIToUTF16("foo1")); |
| 70 menu_model()->AddItem(1, ASCIIToUTF16("foo2")); | 69 menu_model()->AddItem(1, ASCIIToUTF16("foo2")); |
| 71 | 70 |
| 72 ui::Accelerator test_accel(ui::VKEY_A, ui::EF_NONE); | 71 ui::Accelerator test_accel(ui::VKEY_A, ui::EF_NONE); |
| 73 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 72 gfx::Image test_image1 = gfx::test::CreateImage(16, 16); |
| 74 gfx::Image test_image1(*rb.GetImageSkiaNamed(IDR_STATUS_TRAY_ICON)); | |
| 75 ui::Accelerator accel_arg; | 73 ui::Accelerator accel_arg; |
| 76 gfx::Image image_arg; | 74 gfx::Image image_arg; |
| 77 | 75 |
| 78 EXPECT_FALSE(menu_model()->GetAcceleratorForCommandId(0, &accel_arg)); | 76 EXPECT_FALSE(menu_model()->GetAcceleratorForCommandId(0, &accel_arg)); |
| 79 EXPECT_FALSE(menu_model()->GetIconForCommandId(0, &image_arg)); | 77 EXPECT_FALSE(menu_model()->GetIconForCommandId(0, &image_arg)); |
| 80 EXPECT_FALSE(menu_model()->IsItemForCommandIdDynamic(0)); | 78 EXPECT_FALSE(menu_model()->IsItemForCommandIdDynamic(0)); |
| 81 | 79 |
| 82 // Set the accelerator and label for the first menu item. | 80 // Set the accelerator and label for the first menu item. |
| 83 menu_model()->SetAcceleratorForCommandId(0, &test_accel); | 81 menu_model()->SetAcceleratorForCommandId(0, &test_accel); |
| 84 EXPECT_TRUE(menu_model()->GetAcceleratorForCommandId(0, &accel_arg)); | 82 EXPECT_TRUE(menu_model()->GetAcceleratorForCommandId(0, &accel_arg)); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 103 | 101 |
| 104 // Ensure changes to one menu item does not affect the other menu item. | 102 // Ensure changes to one menu item does not affect the other menu item. |
| 105 EXPECT_FALSE(menu_model()->GetAcceleratorForCommandId(1, &accel_arg)); | 103 EXPECT_FALSE(menu_model()->GetAcceleratorForCommandId(1, &accel_arg)); |
| 106 EXPECT_EQ(base::string16(), menu_model()->GetLabelForCommandId(1)); | 104 EXPECT_EQ(base::string16(), menu_model()->GetLabelForCommandId(1)); |
| 107 EXPECT_EQ(base::string16(), menu_model()->GetSublabelForCommandId(0)); | 105 EXPECT_EQ(base::string16(), menu_model()->GetSublabelForCommandId(0)); |
| 108 EXPECT_FALSE(menu_model()->GetIconForCommandId(0, &image_arg)); | 106 EXPECT_FALSE(menu_model()->GetIconForCommandId(0, &image_arg)); |
| 109 | 107 |
| 110 // Menu state should have changed 7 times in this test. | 108 // Menu state should have changed 7 times in this test. |
| 111 EXPECT_EQ(7, changed_count()); | 109 EXPECT_EQ(7, changed_count()); |
| 112 } | 110 } |
| OLD | NEW |