| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #import "ios/web/web_state/web_state_impl.h" | 5 #import "ios/web/web_state/web_state_impl.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 | 10 |
| (...skipping 674 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 685 | 685 |
| 686 // Tests script execution with and without callback. | 686 // Tests script execution with and without callback. |
| 687 TEST_F(WebStateTest, ScriptExecution) { | 687 TEST_F(WebStateTest, ScriptExecution) { |
| 688 LoadHtml("<html></html>"); | 688 LoadHtml("<html></html>"); |
| 689 | 689 |
| 690 // Execute script without callback. | 690 // Execute script without callback. |
| 691 web_state_->ExecuteJavaScript(base::UTF8ToUTF16("window.foo = 'bar'")); | 691 web_state_->ExecuteJavaScript(base::UTF8ToUTF16("window.foo = 'bar'")); |
| 692 | 692 |
| 693 // Execute script with callback. | 693 // Execute script with callback. |
| 694 __block std::unique_ptr<base::Value> execution_result; | 694 __block std::unique_ptr<base::Value> execution_result; |
| 695 __block bool execution_complete = false; |
| 695 web_state_->ExecuteJavaScript(base::UTF8ToUTF16("window.foo"), | 696 web_state_->ExecuteJavaScript(base::UTF8ToUTF16("window.foo"), |
| 696 base::BindBlock(^(const base::Value* value) { | 697 base::BindBlock(^(const base::Value* value) { |
| 697 ASSERT_TRUE(value); | |
| 698 execution_result = value->CreateDeepCopy(); | 698 execution_result = value->CreateDeepCopy(); |
| 699 execution_complete = true; |
| 699 })); | 700 })); |
| 700 base::test::ios::WaitUntilCondition(^bool() { | 701 base::test::ios::WaitUntilCondition(^{ |
| 701 return execution_result.get(); | 702 return execution_complete; |
| 702 }); | 703 }); |
| 703 | 704 |
| 705 ASSERT_TRUE(execution_result); |
| 704 std::string string_result; | 706 std::string string_result; |
| 705 execution_result->GetAsString(&string_result); | 707 execution_result->GetAsString(&string_result); |
| 706 EXPECT_EQ("bar", string_result); | 708 EXPECT_EQ("bar", string_result); |
| 707 } | 709 } |
| 708 | 710 |
| 709 // Tests loading progress. | 711 // Tests loading progress. |
| 710 TEST_F(WebStateTest, LoadingProgress) { | 712 TEST_F(WebStateTest, LoadingProgress) { |
| 711 EXPECT_FLOAT_EQ(0.0, web_state_->GetLoadingProgress()); | 713 EXPECT_FLOAT_EQ(0.0, web_state_->GetLoadingProgress()); |
| 712 LoadHtml("<html></html>"); | 714 LoadHtml("<html></html>"); |
| 713 base::test::ios::WaitUntilCondition(^bool() { | 715 base::test::ios::WaitUntilCondition(^bool() { |
| (...skipping 22 matching lines...) Expand all Loading... |
| 736 "</script>"); | 738 "</script>"); |
| 737 | 739 |
| 738 base::test::ios::WaitUntilCondition(^{ | 740 base::test::ios::WaitUntilCondition(^{ |
| 739 return message_received; | 741 return message_received; |
| 740 }); | 742 }); |
| 741 web_state_->RemoveScriptCommandCallback("test"); | 743 web_state_->RemoveScriptCommandCallback("test"); |
| 742 } | 744 } |
| 743 | 745 |
| 744 } // namespace | 746 } // namespace |
| 745 } // namespace web | 747 } // namespace web |
| OLD | NEW |