| OLD | NEW |
| 1 // Copyright (c) 2009 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 CHROME_BROWSER_UI_COCOA_INFOBARS_INFOBAR_TEST_HELPER_H_ |
| 6 #define CHROME_BROWSER_UI_COCOA_INFOBARS_INFOBAR_TEST_HELPER_H_ |
| 7 #pragma once |
| 8 |
| 5 #include "chrome/browser/tab_contents/infobar_delegate.h" | 9 #include "chrome/browser/tab_contents/infobar_delegate.h" |
| 6 | 10 |
| 7 #include "base/utf_string_conversions.h" | |
| 8 | 11 |
| 9 namespace { | 12 // MockAlertInfoBarDelegate --------------------------------------------------- |
| 10 const char kMockAlertInfoBarMessage[] = "MockAlertInfoBarMessage"; | |
| 11 const char kMockLinkInfoBarMessage[] = "MockLinkInfoBarMessage"; | |
| 12 const char kMockLinkInfoBarLink[] = "http://dev.chromium.org"; | |
| 13 const char kMockConfirmInfoBarMessage[] = "MockConfirmInfoBarMessage"; | |
| 14 } | |
| 15 | |
| 16 ////////////////////////////////////////////////////////////////////////// | |
| 17 // Mock InfoBarDelgates | |
| 18 | 13 |
| 19 class MockAlertInfoBarDelegate : public AlertInfoBarDelegate { | 14 class MockAlertInfoBarDelegate : public AlertInfoBarDelegate { |
| 20 public: | 15 public: |
| 21 explicit MockAlertInfoBarDelegate() | 16 MockAlertInfoBarDelegate(); |
| 22 : AlertInfoBarDelegate(NULL), | 17 virtual ~MockAlertInfoBarDelegate(); |
| 23 message_text_accessed(false), | |
| 24 icon_accessed(false), | |
| 25 closed(false) { | |
| 26 } | |
| 27 | 18 |
| 28 virtual string16 GetMessageText() const { | 19 bool icon_accessed() const { return icon_accessed_; } |
| 29 message_text_accessed = true; | 20 bool message_text_accessed() const { return message_text_accessed_; } |
| 30 return ASCIIToUTF16(kMockAlertInfoBarMessage); | 21 bool closed() const { return closed_; } |
| 31 } | |
| 32 | 22 |
| 33 virtual SkBitmap* GetIcon() const { | 23 static const char kMessage[]; |
| 34 icon_accessed = true; | |
| 35 return NULL; | |
| 36 } | |
| 37 | 24 |
| 38 virtual void InfoBarClosed() { | 25 private: |
| 39 closed = true; | 26 // AlertInfoBarDelegate |
| 40 } | 27 virtual void InfoBarClosed(); |
| 28 virtual SkBitmap* GetIcon() const; |
| 29 virtual string16 GetMessageText() const; |
| 41 | 30 |
| 42 // These are declared mutable to get around const-ness issues. | 31 mutable bool icon_accessed_; |
| 43 mutable bool message_text_accessed; | 32 mutable bool message_text_accessed_; |
| 44 mutable bool icon_accessed; | 33 bool closed_; |
| 45 bool closed; | 34 |
| 35 DISALLOW_COPY_AND_ASSIGN(MockAlertInfoBarDelegate); |
| 46 }; | 36 }; |
| 47 | 37 |
| 38 |
| 39 // MockLinkInfoBarDelegate ---------------------------------------------------- |
| 40 |
| 48 class MockLinkInfoBarDelegate : public LinkInfoBarDelegate { | 41 class MockLinkInfoBarDelegate : public LinkInfoBarDelegate { |
| 49 public: | 42 public: |
| 50 explicit MockLinkInfoBarDelegate() | 43 MockLinkInfoBarDelegate(); |
| 51 : LinkInfoBarDelegate(NULL), | 44 virtual ~MockLinkInfoBarDelegate(); |
| 52 message_text_accessed(false), | |
| 53 link_text_accessed(false), | |
| 54 icon_accessed(false), | |
| 55 link_clicked(false), | |
| 56 closed(false), | |
| 57 closes_on_action(true) { | |
| 58 } | |
| 59 | 45 |
| 60 virtual string16 GetMessageTextWithOffset(size_t* link_offset) const { | 46 void set_dont_close_on_action() { closes_on_action_ = false; } |
| 61 message_text_accessed = true; | |
| 62 return ASCIIToUTF16(kMockLinkInfoBarMessage); | |
| 63 } | |
| 64 | 47 |
| 65 virtual string16 GetLinkText() const { | 48 bool icon_accessed() const { return icon_accessed_; } |
| 66 link_text_accessed = true; | 49 bool message_text_accessed() const { return message_text_accessed_; } |
| 67 return ASCIIToUTF16(kMockLinkInfoBarLink); | 50 bool link_text_accessed() const { return link_text_accessed_; } |
| 68 } | 51 bool link_clicked() const { return link_clicked_; } |
| 52 bool closed() const { return closed_; } |
| 69 | 53 |
| 70 virtual SkBitmap* GetIcon() const { | 54 static const char kMessage[]; |
| 71 icon_accessed = true; | 55 static const char kLink[]; |
| 72 return NULL; | |
| 73 } | |
| 74 | 56 |
| 75 virtual bool LinkClicked(WindowOpenDisposition disposition) { | 57 private: |
| 76 link_clicked = true; | 58 // LinkInfoBarDelegate |
| 77 return closes_on_action; | 59 virtual void InfoBarClosed(); |
| 78 } | 60 virtual SkBitmap* GetIcon() const; |
| 79 | 61 virtual string16 GetMessageTextWithOffset(size_t* link_offset) const; |
| 80 virtual void InfoBarClosed() { | 62 virtual string16 GetLinkText() const; |
| 81 closed = true; | 63 virtual bool LinkClicked(WindowOpenDisposition disposition); |
| 82 } | |
| 83 | |
| 84 // These are declared mutable to get around const-ness issues. | |
| 85 mutable bool message_text_accessed; | |
| 86 mutable bool link_text_accessed; | |
| 87 mutable bool icon_accessed; | |
| 88 bool link_clicked; | |
| 89 bool closed; | |
| 90 | 64 |
| 91 // Determines whether the infobar closes when an action is taken or not. | 65 // Determines whether the infobar closes when an action is taken or not. |
| 92 bool closes_on_action; | 66 bool closes_on_action_; |
| 67 |
| 68 mutable bool icon_accessed_; |
| 69 mutable bool message_text_accessed_; |
| 70 mutable bool link_text_accessed_; |
| 71 bool link_clicked_; |
| 72 bool closed_; |
| 73 |
| 74 DISALLOW_COPY_AND_ASSIGN(MockLinkInfoBarDelegate); |
| 93 }; | 75 }; |
| 94 | 76 |
| 77 |
| 78 // MockConfirmInfoBarDelegate ------------------------------------------------- |
| 79 |
| 95 class MockConfirmInfoBarDelegate : public ConfirmInfoBarDelegate { | 80 class MockConfirmInfoBarDelegate : public ConfirmInfoBarDelegate { |
| 96 public: | 81 public: |
| 97 explicit MockConfirmInfoBarDelegate() | 82 MockConfirmInfoBarDelegate(); |
| 98 : ConfirmInfoBarDelegate(NULL), | 83 virtual ~MockConfirmInfoBarDelegate(); |
| 99 message_text_accessed(false), | |
| 100 link_text_accessed(false), | |
| 101 icon_accessed(false), | |
| 102 ok_clicked(false), | |
| 103 cancel_clicked(false), | |
| 104 link_clicked(false), | |
| 105 closed(false), | |
| 106 closes_on_action(true) { | |
| 107 } | |
| 108 | 84 |
| 109 virtual int GetButtons() const { | 85 void set_dont_close_on_action() { closes_on_action_ = false; } |
| 110 return (BUTTON_OK | BUTTON_CANCEL); | |
| 111 } | |
| 112 | 86 |
| 113 virtual string16 GetButtonLabel(InfoBarButton button) const { | 87 bool icon_accessed() const { return icon_accessed_; } |
| 114 if (button == BUTTON_OK) | 88 bool message_text_accessed() const { return message_text_accessed_; } |
| 115 return ASCIIToUTF16("OK"); | 89 bool link_text_accessed() const { return link_text_accessed_; } |
| 116 else | 90 bool ok_clicked() const { return ok_clicked_; } |
| 117 return ASCIIToUTF16("Cancel"); | 91 bool cancel_clicked() const { return cancel_clicked_; } |
| 118 } | 92 bool link_clicked() const { return link_clicked_; } |
| 93 bool closed() const { return closed_; } |
| 119 | 94 |
| 120 virtual bool Accept() { | 95 static const char kMessage[]; |
| 121 ok_clicked = true; | |
| 122 return closes_on_action; | |
| 123 } | |
| 124 | 96 |
| 125 virtual bool Cancel() { | 97 private: |
| 126 cancel_clicked = true; | 98 // ConfirmInfoBarDelegate |
| 127 return closes_on_action; | 99 virtual void InfoBarClosed(); |
| 128 } | 100 virtual SkBitmap* GetIcon() const; |
| 129 | 101 virtual string16 GetMessageText() const; |
| 130 virtual string16 GetMessageText() const { | 102 virtual int GetButtons() const; |
| 131 message_text_accessed = true; | 103 virtual string16 GetButtonLabel(InfoBarButton button) const; |
| 132 return ASCIIToUTF16(kMockConfirmInfoBarMessage); | 104 virtual bool Accept(); |
| 133 } | 105 virtual bool Cancel(); |
| 134 | 106 virtual string16 GetLinkText(); |
| 135 virtual SkBitmap* GetIcon() const { | 107 virtual bool LinkClicked(WindowOpenDisposition disposition); |
| 136 icon_accessed = true; | |
| 137 return NULL; | |
| 138 } | |
| 139 | |
| 140 virtual void InfoBarClosed() { | |
| 141 closed = true; | |
| 142 } | |
| 143 | |
| 144 virtual string16 GetLinkText() { | |
| 145 link_text_accessed = true; | |
| 146 return string16(); | |
| 147 } | |
| 148 | |
| 149 virtual bool LinkClicked(WindowOpenDisposition disposition) { | |
| 150 link_clicked = true; | |
| 151 return closes_on_action; | |
| 152 } | |
| 153 | |
| 154 // These are declared mutable to get around const-ness issues. | |
| 155 mutable bool message_text_accessed; | |
| 156 mutable bool link_text_accessed; | |
| 157 mutable bool icon_accessed; | |
| 158 bool ok_clicked; | |
| 159 bool cancel_clicked; | |
| 160 bool link_clicked; | |
| 161 bool closed; | |
| 162 | 108 |
| 163 // Determines whether the infobar closes when an action is taken or not. | 109 // Determines whether the infobar closes when an action is taken or not. |
| 164 bool closes_on_action; | 110 bool closes_on_action_; |
| 111 |
| 112 mutable bool icon_accessed_; |
| 113 mutable bool message_text_accessed_; |
| 114 mutable bool link_text_accessed_; |
| 115 bool ok_clicked_; |
| 116 bool cancel_clicked_; |
| 117 bool link_clicked_; |
| 118 bool closed_; |
| 119 |
| 120 DISALLOW_COPY_AND_ASSIGN(MockConfirmInfoBarDelegate); |
| 165 }; | 121 }; |
| 122 |
| 123 #endif // CHROME_BROWSER_UI_COCOA_INFOBARS_INFOBAR_TEST_HELPER_H_ |
| OLD | NEW |