| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #include "base/base64.h" | 5 #include "base/base64.h" |
| 6 #include "base/files/file_path.h" | 6 #include "base/files/file_path.h" |
| 7 #include "base/json/json_reader.h" | 7 #include "base/json/json_reader.h" |
| 8 #include "base/json/json_writer.h" | 8 #include "base/json/json_writer.h" |
| 9 #include "base/path_service.h" | 9 #include "base/path_service.h" |
| 10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
| (...skipping 911 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 922 "});", receiver->id().c_str()))); | 922 "});", receiver->id().c_str()))); |
| 923 | 923 |
| 924 EXPECT_EQ("true", | 924 EXPECT_EQ("true", |
| 925 ExecuteScriptInBackgroundPage(sender->id(), | 925 ExecuteScriptInBackgroundPage(sender->id(), |
| 926 base::StringPrintf( | 926 base::StringPrintf( |
| 927 "chrome.test.runWithUserGesture(function() {\n" | 927 "chrome.test.runWithUserGesture(function() {\n" |
| 928 " chrome.runtime.sendMessage('%s', {}, function(response) {\n" | 928 " chrome.runtime.sendMessage('%s', {}, function(response) {\n" |
| 929 " window.domAutomationController.send('' + response.result);\n" | 929 " window.domAutomationController.send('' + response.result);\n" |
| 930 " });\n" | 930 " });\n" |
| 931 "});", receiver->id().c_str()))); | 931 "});", receiver->id().c_str()))); |
| 932 |
| 933 // Messges sent from a setTimeout handler should not forward the user gesture |
| 934 // again. |
| 935 EXPECT_EQ( |
| 936 "false", |
| 937 ExecuteScriptInBackgroundPage( |
| 938 sender->id(), |
| 939 base::StringPrintf( |
| 940 "chrome.test.runWithUserGesture(function() {\n" |
| 941 " window.setTimeout(function() {\n" |
| 942 " chrome.runtime.sendMessage('%s', {}, function(response) {\n" |
| 943 " window.domAutomationController.send('' + " |
| 944 " response.result);\n" |
| 945 " });\n" |
| 946 " }, 0);\n" |
| 947 "});", |
| 948 receiver->id().c_str()))); |
| 949 |
| 950 // The user gesture should not be send back with the reply message, gestures |
| 951 // are only forwarded once. |
| 952 EXPECT_EQ( |
| 953 "false", |
| 954 ExecuteScriptInBackgroundPage( |
| 955 sender->id(), |
| 956 base::StringPrintf( |
| 957 "chrome.test.runWithUserGesture(function() {\n" |
| 958 " chrome.runtime.sendMessage('%s', {}, function(response) {\n" |
| 959 " window.domAutomationController.send('' + " |
| 960 " chrome.test.isProcessingUserGesture());\n" |
| 961 " });\n" |
| 962 "});", |
| 963 receiver->id().c_str()))); |
| 932 } | 964 } |
| 933 | 965 |
| 934 // Tests that a hosted app on a connectable site doesn't interfere with the | 966 // Tests that a hosted app on a connectable site doesn't interfere with the |
| 935 // connectability of that site. | 967 // connectability of that site. |
| 936 IN_PROC_BROWSER_TEST_F(ExternallyConnectableMessagingTest, HostedAppOnWebsite) { | 968 IN_PROC_BROWSER_TEST_F(ExternallyConnectableMessagingTest, HostedAppOnWebsite) { |
| 937 InitializeTestServer(); | 969 InitializeTestServer(); |
| 938 | 970 |
| 939 LoadChromiumHostedApp(); | 971 LoadChromiumHostedApp(); |
| 940 | 972 |
| 941 // The presence of the hosted app shouldn't give the ability to send messages. | 973 // The presence of the hosted app shouldn't give the ability to send messages. |
| (...skipping 23 matching lines...) Expand all Loading... |
| 965 ui_test_utils::NavigateToURL(browser(), chromium_org_url()); | 997 ui_test_utils::NavigateToURL(browser(), chromium_org_url()); |
| 966 EXPECT_EQ(COULD_NOT_ESTABLISH_CONNECTION_ERROR , | 998 EXPECT_EQ(COULD_NOT_ESTABLISH_CONNECTION_ERROR , |
| 967 CanConnectAndSendMessagesToMainFrame("invalid")); | 999 CanConnectAndSendMessagesToMainFrame("invalid")); |
| 968 } | 1000 } |
| 969 | 1001 |
| 970 #endif // !defined(OS_WIN) - http://crbug.com/350517. | 1002 #endif // !defined(OS_WIN) - http://crbug.com/350517. |
| 971 | 1003 |
| 972 } // namespace | 1004 } // namespace |
| 973 | 1005 |
| 974 }; // namespace extensions | 1006 }; // namespace extensions |
| OLD | NEW |