Index: ios/web/web_state/web_state_impl_unittest.mm |
diff --git a/ios/web/web_state/web_state_impl_unittest.mm b/ios/web/web_state/web_state_impl_unittest.mm |
index 58a1b114d7eec5303319386f34db90baa55cb360..7ff65aba57207bf5d4b3f17542c5a05f92c933ca 100644 |
--- a/ios/web/web_state/web_state_impl_unittest.mm |
+++ b/ios/web/web_state/web_state_impl_unittest.mm |
@@ -18,6 +18,7 @@ |
#include "ios/web/public/load_committed_details.h" |
#include "ios/web/public/test/test_browser_state.h" |
#include "ios/web/public/test/web_test.h" |
+#include "ios/web/public/web_state/context_menu_params.h" |
#include "ios/web/public/web_state/global_web_state_observer.h" |
#include "ios/web/public/web_state/web_state_delegate.h" |
#include "ios/web/public/web_state/web_state_observer.h" |
@@ -116,21 +117,48 @@ class TestGlobalWebStateObserver : public GlobalWebStateObserver { |
// expected. |
class TestWebStateDelegate : public WebStateDelegate { |
public: |
- TestWebStateDelegate() : load_progress_changed_called_(false) {} |
+ TestWebStateDelegate() |
+ : load_progress_changed_called_(false), |
+ handle_context_menu_called_(false), |
+ get_java_script_dialog_presenter_called_(false) {} |
- // Methods returning true if the corresponding WebStateObserver method has |
- // been called. |
+ // True if the WebStateDelegate LoadProgressChanged method has been called. |
bool load_progress_changed_called() const { |
return load_progress_changed_called_; |
} |
+ // True if the WebStateDelegate HandleContextMenu method has been called. |
+ bool handle_context_menu_called() const { |
+ return handle_context_menu_called_; |
+ } |
+ |
+ // True if the WebStateDelegate GetJavaScriptDialogPresenter method has been |
+ // called. |
+ bool get_java_script_dialog_presenter_called() const { |
+ return get_java_script_dialog_presenter_called_; |
+ } |
+ |
private: |
- // WebStateObserver implementation: |
+ // WebStateDelegate implementation: |
void LoadProgressChanged(WebState* source, double progress) override { |
load_progress_changed_called_ = true; |
} |
+ bool HandleContextMenu(WebState* source, |
+ const ContextMenuParams& params) override { |
+ handle_context_menu_called_ = true; |
+ return NO; |
+ } |
+ |
+ JavaScriptDialogPresenter* GetJavaScriptDialogPresenter( |
+ WebState* source) override { |
+ get_java_script_dialog_presenter_called_ = true; |
+ return nullptr; |
Eugene But (OOO till 7-30)
2016/06/28 18:14:48
How about adding SetJavaScriptDialogPresenter and
michaeldo
2016/06/28 21:58:27
I like that idea. Done.
|
+ } |
+ |
bool load_progress_changed_called_; |
+ bool handle_context_menu_called_; |
+ bool get_java_script_dialog_presenter_called_; |
}; |
// Test observer to check that the WebStateObserver methods are called as |
@@ -415,6 +443,24 @@ TEST_F(WebStateTest, DelegateTest) { |
EXPECT_FALSE(delegate.load_progress_changed_called()); |
web_state_->SendChangeLoadProgress(0.0); |
EXPECT_TRUE(delegate.load_progress_changed_called()); |
+ |
+ // Test that HandleContextMenu() is called. |
+ EXPECT_FALSE(delegate.handle_context_menu_called()); |
+ web::ContextMenuParams context_menu_params; |
+ web_state_->HandleContextMenu(context_menu_params); |
+ EXPECT_TRUE(delegate.handle_context_menu_called()); |
+ |
+ // Test that GetJavaScriptDialogPresenter() is called. |
+ EXPECT_FALSE(delegate.get_java_script_dialog_presenter_called()); |
+ __block bool callback_called = false; |
+ web_state_->RunJavaScriptDialog(GURL(), JAVASCRIPT_DIALOG_TYPE_ALERT, @"", |
+ nil, base::BindBlock(^(BOOL, NSString*) { |
+ callback_called = true; |
+ })); |
+ EXPECT_TRUE(delegate.get_java_script_dialog_presenter_called()); |
+ // Callback will be immediately run since we provide no presenter in |
+ // our TestWebStateDelegate's |GetJavaScriptDialogPresenter| method. |
+ EXPECT_TRUE(callback_called); |
} |
// Verifies that GlobalWebStateObservers are called when expected. |