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

Side by Side Diff: chrome/browser/page_menu_model_unittest.cc

Issue 465130: Share the code that builds the page menu in a common model, make Mac and Win ... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 11 years 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/page_menu_model.cc ('k') | chrome/browser/views/toolbar_view.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Property Changes:
Name: svn:eol-style
+ LF
OLDNEW
(Empty)
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. Use of this
2 // source code is governed by a BSD-style license that can be found in the
3 // LICENSE file.
4
5 #include "chrome/browser/page_menu_model.h"
6
7 #include "base/logging.h"
8 #include "chrome/test/browser_with_test_window_test.h"
9 #include "testing/gtest/include/gtest/gtest.h"
10
11 // A menu delegate that counts the number of times certain things are called
12 // to make sure things are hooked up properly.
13 class Delegate : public menus::SimpleMenuModel::Delegate {
14 public:
15 Delegate() : execute_count_(0), enable_count_(0) { }
16
17 virtual bool IsCommandIdChecked(int command_id) const { return false; }
18 virtual bool IsCommandIdEnabled(int command_id) const {
19 ++enable_count_;
20 return true;
21 }
22 virtual bool GetAcceleratorForCommandId(
23 int command_id,
24 menus::Accelerator* accelerator) { return false; }
25 virtual void ExecuteCommand(int command_id) { ++execute_count_; }
26
27 int execute_count_;
28 mutable int enable_count_;
29 };
30
31 class PageMenuModelTest : public BrowserWithTestWindowTest {
32 public:
33 };
34
35 TEST_F(PageMenuModelTest, Basics) {
36 Delegate delegate;
37 PageMenuModel model(&delegate, browser());
38
39 // Verify it has items. The number varies by platform, so we don't check
40 // the exact number.
41 EXPECT_GT(model.GetItemCount(), 10);
42
43 // Execute a couple of the items and make sure it gets back to our delegate.
44 model.ActivatedAt(0);
45 EXPECT_TRUE(model.IsEnabledAt(0));
46 model.ActivatedAt(3);
47 EXPECT_TRUE(model.IsEnabledAt(3));
48 EXPECT_EQ(delegate.execute_count_, 2);
49 EXPECT_EQ(delegate.enable_count_, 2);
50
51 delegate.execute_count_ = 0;
52 delegate.enable_count_ = 0;
53
54 // Choose something from the zoom submenu and make sure it makes it back to
55 // the delegate as well.
56 menus::MenuModel* zoomModel = model.GetSubmenuModelAt(10);
57 EXPECT_TRUE(zoomModel);
58 EXPECT_GT(zoomModel->GetItemCount(), 1);
59 zoomModel->ActivatedAt(1);
60 EXPECT_TRUE(zoomModel->IsEnabledAt(1));
61 EXPECT_EQ(delegate.execute_count_, 1);
62 EXPECT_EQ(delegate.enable_count_, 1);
63 }
OLDNEW
« no previous file with comments | « chrome/browser/page_menu_model.cc ('k') | chrome/browser/views/toolbar_view.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698