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 #ifndef UI_BASE_TEST_UI_COCOA_TEST_HELPER_H_ | 5 #ifndef UI_BASE_TEST_UI_COCOA_TEST_HELPER_H_ |
6 #define UI_BASE_TEST_UI_COCOA_TEST_HELPER_H_ | 6 #define UI_BASE_TEST_UI_COCOA_TEST_HELPER_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <set> | 9 #include <set> |
10 | 10 |
11 #import <Cocoa/Cocoa.h> | 11 #import <Cocoa/Cocoa.h> |
12 | 12 |
| 13 #include "base/compiler_specific.h" |
13 #import "base/mac/scoped_nsautorelease_pool.h" | 14 #import "base/mac/scoped_nsautorelease_pool.h" |
14 #include "testing/platform_test.h" | 15 #include "testing/platform_test.h" |
15 | 16 |
16 // Background windows normally will not display things such as focus | 17 // Background windows normally will not display things such as focus |
17 // rings. This class allows -isKeyWindow to be manipulated to test | 18 // rings. This class allows -isKeyWindow to be manipulated to test |
18 // such things. | 19 // such things. |
19 @interface CocoaTestHelperWindow : NSWindow { | 20 @interface CocoaTestHelperWindow : NSWindow { |
20 @private | 21 @private |
21 BOOL pretendIsKeyWindow_; | 22 BOOL pretendIsKeyWindow_; |
22 } | 23 } |
(...skipping 29 matching lines...) Expand all Loading... |
52 public: | 53 public: |
53 CocoaTest(); | 54 CocoaTest(); |
54 virtual ~CocoaTest(); | 55 virtual ~CocoaTest(); |
55 | 56 |
56 // Must be called by subclasses that override TearDown. We verify that it | 57 // Must be called by subclasses that override TearDown. We verify that it |
57 // is called in our destructor. Takes care of making sure that all windows | 58 // is called in our destructor. Takes care of making sure that all windows |
58 // are closed off correctly. If your tests open windows, they must be sure | 59 // are closed off correctly. If your tests open windows, they must be sure |
59 // to close them before CocoaTest::TearDown is called. A standard way of doing | 60 // to close them before CocoaTest::TearDown is called. A standard way of doing |
60 // this would be to create them in SetUp (after calling CocoaTest::Setup) and | 61 // this would be to create them in SetUp (after calling CocoaTest::Setup) and |
61 // then close them in TearDown before calling CocoaTest::TearDown. | 62 // then close them in TearDown before calling CocoaTest::TearDown. |
62 virtual void TearDown(); | 63 virtual void TearDown() OVERRIDE; |
63 | 64 |
64 // Retuns a test window that can be used by views and other UI objects | 65 // Retuns a test window that can be used by views and other UI objects |
65 // as part of their tests. Is created lazily, and will be closed correctly | 66 // as part of their tests. Is created lazily, and will be closed correctly |
66 // in CocoaTest::TearDown. Note that it is a CocoaTestHelperWindow which | 67 // in CocoaTest::TearDown. Note that it is a CocoaTestHelperWindow which |
67 // has special handling for being Key. | 68 // has special handling for being Key. |
68 CocoaTestHelperWindow* test_window(); | 69 CocoaTestHelperWindow* test_window(); |
69 | 70 |
70 protected: | 71 protected: |
71 // Allows subclasses to do initialization before calling through to the base | 72 // Allows subclasses to do initialization before calling through to the base |
72 // class's initialization. | 73 // class's initialization. |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 #define EXPECT_NSRECT_EQ(expected, actual) \ | 141 #define EXPECT_NSRECT_EQ(expected, actual) \ |
141 EXPECT_TRUE(CGFLOAT_EQ(expected.origin.x, actual.origin.x) && \ | 142 EXPECT_TRUE(CGFLOAT_EQ(expected.origin.x, actual.origin.x) && \ |
142 CGFLOAT_EQ(expected.origin.y, actual.origin.y) && \ | 143 CGFLOAT_EQ(expected.origin.y, actual.origin.y) && \ |
143 CGFLOAT_EQ(expected.size.width, actual.size.width) && \ | 144 CGFLOAT_EQ(expected.size.width, actual.size.width) && \ |
144 CGFLOAT_EQ(expected.size.height, actual.size.height)) << \ | 145 CGFLOAT_EQ(expected.size.height, actual.size.height)) << \ |
145 "Rects do not match: " << \ | 146 "Rects do not match: " << \ |
146 [NSStringFromRect(expected) UTF8String] << \ | 147 [NSStringFromRect(expected) UTF8String] << \ |
147 " != " << [NSStringFromRect(actual) UTF8String] | 148 " != " << [NSStringFromRect(actual) UTF8String] |
148 | 149 |
149 #endif // UI_BASE_TEST_UI_COCOA_TEST_HELPER_H_ | 150 #endif // UI_BASE_TEST_UI_COCOA_TEST_HELPER_H_ |
OLD | NEW |