def test2a_chrome_extension_initialization_with_two_extensions(self): """ emit browser with 2 extensions - test_extension and ros_window_ready """ self.director_publisher.publish( self.message_factory._get_message( 'test_one_browser_with_two_extensions_and_preloading_msg')) wait_for_assert_equal( len(self.director_window_ready_mock.messages) > 0, True, timeout=self.preloading_grace_time) self.assertEqual( len(self.director_window_ready_mock.messages) > 0, True) self.assertEqual(len(self.director_ready_mock.messages), 1) self.assertEqual( len(self.browser_service_mock_left.messages[0].browsers), 0) self.assertEqual( self.browser_service_mock_center.messages[0].browsers[0]. extensions[0].name, 'test_extension1') self.assertEqual( self.browser_service_mock_center.messages[0].browsers[0]. extensions[1].name, 'test_extension2') browsers_on_center = self.get_browsers_thru_service('center') # Two extensions, +ros_window_ready +url_monitor self.assertEqual(len(browsers_on_center.items()[0][1]['extensions']), 4) # cleanup self.director_publisher.publish( self.message_factory._get_message('test_no_browsers_msg')) rospy.sleep(self.message_emission_grace_time)
def test9_adhoc_browser_custom_preload_event(self): """ Test sending custom event from the extension instead of sending readiness message upon standard onDomReady """ self.director_publisher.publish( self.message_factory._get_message( 'test_one_browser_with_preloading_and_custom_preloading_event_msg' )) rospy.sleep(self.message_emission_grace_time) wait_for_assert_equal(len(self.director_ready_mock.messages), 1, self.preloading_grace_time) self.assertEqual( len(self.browser_service_mock_common.messages[0].browsers), 1) self.assertEqual(len(self.director_ready_mock.messages), 1) rospy.wait_for_service('/browser_service/center') center_service = rospy.ServiceProxy('/browser_service/center', BrowserPool) browsers_on_center = center_service().state try: browsers_on_center = json.loads(browsers_on_center) json_is_valid = True except ValueError: browsers_on_center = {} json_is_valid = False self.assertEqual(json_is_valid, True) self.assertEqual(len(browsers_on_center), 1)
def test_3_extension_gets_passed_to_chrome_cmdline(self): self.reinitialize_mock_subscribers() self.director_publisher.publish( self.message_factory._get_message( 'test_one_browser_with_allowed_urls_msg')) rospy.wait_for_service('/browser_service/center') center_service = rospy.ServiceProxy('/browser_service/center', BrowserPool) wait_for_assert_equal(len(json.loads(center_service().state)), 1, self.loading_grace_time) browsers_on_center = json.loads(center_service().state) self.assertEqual(len(browsers_on_center), 1) self.assertEqual( 'monitor_page_urls' in browsers_on_center.items()[0][1]['extensions'][0], True) self.assertEqual( 'allowed_urls=google.com' in browsers_on_center.items()[0][1]['url'], True) self.assertEqual( 'allowed_urls=endpoint.com' in browsers_on_center.items()[0][1]['url'], True) # cleanup self.director_publisher.publish( self.message_factory._get_message('test_no_browsers_msg')) rospy.sleep(self.message_emission_grace_time)
def test9_adhoc_browser_custom_preload_event(self): """ Test sending custom event from the extension instead of sending readiness message upon standard onDomReady """ self.director_publisher.publish(self.message_factory._get_message('test_one_browser_with_preloading_and_custom_preloading_event_msg')) rospy.sleep(self.message_emission_grace_time) wait_for_assert_equal(len(self.director_ready_mock.messages), 1, self.preloading_grace_time) self.assertEqual(len(self.browser_service_mock_common.messages[0].browsers), 1) self.assertEqual(len(self.director_ready_mock.messages), 1) rospy.wait_for_service('/browser_service/center') center_service = rospy.ServiceProxy('/browser_service/center', BrowserPool) browsers_on_center = center_service().state try: browsers_on_center = json.loads(browsers_on_center) json_is_valid = True except ValueError: browsers_on_center = {} json_is_valid = False self.assertEqual(json_is_valid, True) self.assertEqual(len(browsers_on_center), 1)
def test9b_adhoc_browser_readiness_handbrake(self): """ Tests one browser with wrong URL Ready message should come after readiness handbrake timeout of 10 seconds (default) """ self.director_publisher.publish(self.message_factory._get_message('test_one_browser_with_preloading_and_wrong_url_msg')) rospy.sleep(self.message_emission_grace_time) wait_for_assert_equal(len(self.director_ready_mock.messages) > 0, True, self.preloading_grace_time) self.assertEqual(len(self.director_ready_mock.messages), 1) self.assertEqual(len(self.director_scene_mock.messages), 1) self.assertEqual(len(self.browser_service_mock_left.messages[0].browsers), 0) self.assertEqual(len(self.browser_service_mock_right.messages[0].browsers), 0) self.assertEqual(len(self.browser_service_mock_center.messages[0].browsers), 1) self.assertEqual(len(self.browser_service_mock_common.messages[0].browsers), 1) rospy.wait_for_service('/browser_service/center') center_service = rospy.ServiceProxy('/browser_service/center', BrowserPool) browsers_on_center = center_service().state try: browsers_on_center = json.loads(browsers_on_center) json_is_valid = True except ValueError: browsers_on_center = {} json_is_valid = False self.assertEqual(json_is_valid, True) self.assertEqual(len(browsers_on_center), 1)
def test3_chrome_commandline_argument_passing(self): """ 1. emit browser with custom command line args - verify that they've been added to cmdargs """ # 1 self.director_publisher.publish(self.message_factory._get_message('test_one_browser_with_custom_cmdargs_msg')) rospy.sleep(self.message_emission_grace_time) self.assertEqual(len(self.director_window_ready_mock.messages), 0) self.assertEqual(len(self.director_ready_mock.messages), 0) self.assertEqual(len(self.director_scene_mock.messages), 1) self.assertEqual(self.browser_service_mock_center.messages[0].browsers[0].command_line_args[0].argument, "--disable-out-of-process-pac") self.assertEqual(self.browser_service_mock_center.messages[0].browsers[0].command_line_args[1].argument, "--enable-benchmarking") self.assertEqual(self.browser_service_mock_center.messages[0].browsers[0].command_line_args[2].argument, "--enable-crash-reporter") self.assertEqual(len(self.browser_service_mock_left.messages[0].browsers), 0) wait_for_assert_equal(len(self.get_browsers_thru_service('center').items()), 1, self.preloading_grace_time) browsers_on_center = self.get_browsers_thru_service('center') self.assertEqual('--disable-out-of-process-pac' in browsers_on_center.items()[0][1]['command_line_args'], True) self.assertEqual('--enable-benchmarking' in browsers_on_center.items()[0][1]['command_line_args'], True) self.assertEqual('--enable-crash-reporter' in browsers_on_center.items()[0][1]['command_line_args'], True)
def test6_chrome_persistence(self): """ 1. emit one browser without preloading - make service assert 2. emit the same message again and verify that they havent been updated 3. emit same message but with a different slug - verify that they havent been touched """ # 1 self.director_publisher.publish(self.message_factory._get_message('test_one_browser_on_center_msg')) rospy.sleep(self.message_emission_grace_time) wait_for_assert_equal(len(self.director_scene_mock.messages), 1, self.preloading_grace_time) # no director window ready should be published self.assertEqual(len(self.director_window_ready_mock.messages), 0) self.assertEqual(len(self.director_ready_mock.messages), 0) self.assertEqual(self.browser_service_mock_center.messages[0].browsers[0].id, 'gzJERcJ') browsers_on_center = self.get_browsers_thru_service('center') # self.assertEqual(browsers_on_center, 'asd') browser_timestamp_before = browsers_on_center['gzJERcJ']['timestamp'] self.assertEqual(browsers_on_center['gzJERcJ']['uid'], 'gzJERcJ') # 2 self.director_publisher.publish(self.message_factory._get_message('test_one_browser_on_center_msg')) rospy.sleep(self.message_emission_grace_time) wait_for_assert_equal(len(self.director_scene_mock.messages), 2, self.preloading_grace_time) self.assertEqual(len(self.director_window_ready_mock.messages), 0) self.assertEqual(len(self.director_ready_mock.messages), 0) self.assertEqual(self.browser_service_mock_center.messages[0].browsers[0].id, 'gzJERcJ') self.assertEqual(self.browser_service_mock_center.messages[1].browsers[0].id, 'gzJERcJ') browsers_on_center = self.get_browsers_thru_service('center') self.assertEqual(len(browsers_on_center.items()), 1) browser_timestamp_after = browsers_on_center.items()[0][1]['timestamp'] self.assertEqual(browsers_on_center['gzJERcJ']['uid'], 'gzJERcJ') self.assertEqual(browser_timestamp_before, browser_timestamp_after, "Emitting same message with identical browser updated the browser instance") # 3 self.director_publisher.publish(self.message_factory._get_message('test_one_browser_on_center_alt_slug_msg')) rospy.sleep(self.message_emission_grace_time) self.assertEqual(len(self.director_ready_mock.messages), 0) self.assertEqual(len(self.director_scene_mock.messages), 3) self.assertEqual(len(self.browser_service_mock_left.messages[0].browsers), 0) self.assertEqual(self.browser_service_mock_center.messages[0].browsers[0].id, 'gzJERcJ') self.assertEqual(self.browser_service_mock_center.messages[1].browsers[0].id, 'gzJERcJ') self.assertEqual(self.browser_service_mock_center.messages[2].browsers[0].id, 'gzJERcJ') browsers_on_center = self.get_browsers_thru_service('center') self.assertEqual(len(browsers_on_center.items()), 1) self.assertEqual(browsers_on_center['gzJERcJ']['uid'], 'gzJERcJ') self.assertEqual(browser_timestamp_before, browser_timestamp_after, "Emitting same message with identical browser updated the browser instance") browser_timestamp_even_after = browsers_on_center.items()[0][1]['timestamp'] self.assertEqual(browser_timestamp_before, browser_timestamp_even_after, "Emitting same message with identical browser but different scene slug updated the browser instance")
def test7_adhoc_browser_preloading(self): """ 1.preloading: a) emit message with preloading - verify readiness message came, make service assert b) emit the same message with preloading again - verify readiness message came, make service assert and confirm that browsers were re-created c) emit the same message but with different slug - verify the same as above d) emit non-preloaded message with different slug and make usual asserts """ # 1a self.director_publisher.publish(self.message_factory._get_message('test_one_browser_with_preloading_msg')) rospy.sleep(self.message_emission_grace_time) wait_for_assert_equal(len(self.director_window_ready_mock.messages) > 0, True, self.preloading_grace_time) self.assertEqual(len(self.director_window_ready_mock.messages) > 0, True) self.assertEqual(len(self.director_scene_mock.messages), 1) self.assertEqual(len(self.director_ready_mock.messages), 1) browsers_on_center = self.get_browsers_thru_service('center') browser_timestamp = browsers_on_center.items()[0][1]['timestamp'] # 1b self.director_publisher.publish(self.message_factory._get_message('test_one_browser_with_preloading_msg')) rospy.sleep(self.message_emission_grace_time) wait_for_assert_equal(len(self.director_ready_mock.messages), 2, self.preloading_grace_time) self.assertEqual(len(self.director_ready_mock.messages), 2) browsers_on_center = self.get_browsers_thru_service('center') self.assertEqual(len(browsers_on_center), 1) browser_timestamp2 = browsers_on_center.items()[0][1]['timestamp'] self.assertNotEqual(browser_timestamp, browser_timestamp2) self.assertGreater(browser_timestamp2, browser_timestamp) # 1c self.director_publisher.publish(self.message_factory._get_message('test_one_browser_with_preloading_alt_slug_msg')) rospy.sleep(self.message_emission_grace_time) wait_for_assert_equal(len(self.director_ready_mock.messages), 3, self.preloading_grace_time) self.assertEqual(len(self.director_ready_mock.messages), 3) browsers_on_center = self.get_browsers_thru_service('center') self.assertEqual(len(browsers_on_center), 1) browser_timestamp3 = browsers_on_center.items()[0][1]['timestamp'] self.assertNotEqual(browser_timestamp2, browser_timestamp3) self.assertGreater(browser_timestamp3, browser_timestamp2) # 1d self.director_publisher.publish(self.message_factory._get_message('test_one_browser_on_center_msg')) rospy.sleep(self.message_emission_grace_time) wait_for_assert_equal(len(self.director_ready_mock.messages), 3, self.preloading_grace_time) self.assertEqual(len(self.director_ready_mock.messages), 3) browsers_on_center = self.get_browsers_thru_service('center') self.assertEqual(len(browsers_on_center), 1) browser_timestamp4 = browsers_on_center.items()[0][1]['timestamp'] self.assertNotEqual(browser_timestamp3, browser_timestamp4) self.assertGreater(browser_timestamp4, browser_timestamp3)
def test_3_extension_gets_passed_to_chrome_cmdline(self): self.reinitialize_mock_subscribers() self.director_publisher.publish(self.message_factory._get_message('test_one_browser_with_allowed_urls_msg')) rospy.wait_for_service('/browser_service/center') center_service = rospy.ServiceProxy('/browser_service/center', BrowserPool) wait_for_assert_equal(len(json.loads(center_service().state)), 1, self.loading_grace_time) browsers_on_center = json.loads(center_service().state) self.assertEqual(len(browsers_on_center), 1) self.assertEqual('monitor_page_urls' in browsers_on_center.items()[0][1]['extensions'][0], True) self.assertEqual('allowed_urls=google.com' in browsers_on_center.items()[0][1]['url'], True) self.assertEqual('allowed_urls=endpoint.com' in browsers_on_center.items()[0][1]['url'], True) # cleanup self.director_publisher.publish(self.message_factory._get_message('test_no_browsers_msg')) rospy.sleep(self.message_emission_grace_time)
def test9b_adhoc_browser_readiness_handbrake(self): """ Tests one browser with wrong URL Ready message should come after readiness handbrake timeout of 10 seconds (default) """ self.director_publisher.publish( self.message_factory._get_message( 'test_one_browser_with_preloading_and_wrong_url_msg')) rospy.sleep(self.message_emission_grace_time) wait_for_assert_equal( len(self.director_ready_mock.messages) > 0, True, self.preloading_grace_time) self.assertEqual(len(self.director_ready_mock.messages), 1) self.assertEqual(len(self.director_scene_mock.messages), 1) self.assertEqual( len(self.browser_service_mock_left.messages[0].browsers), 0) self.assertEqual( len(self.browser_service_mock_right.messages[0].browsers), 0) self.assertEqual( len(self.browser_service_mock_center.messages[0].browsers), 1) self.assertEqual( len(self.browser_service_mock_common.messages[0].browsers), 1) rospy.wait_for_service('/browser_service/center') center_service = rospy.ServiceProxy('/browser_service/center', BrowserPool) browsers_on_center = center_service().state try: browsers_on_center = json.loads(browsers_on_center) json_is_valid = True except ValueError: browsers_on_center = {} json_is_valid = False self.assertEqual(json_is_valid, True) self.assertEqual(len(browsers_on_center), 1)
def test2a_chrome_extension_initialization_with_two_extensions(self): """ emit browser with 2 extensions - test_extension and ros_window_ready """ self.director_publisher.publish(self.message_factory._get_message('test_one_browser_with_two_extensions_and_preloading_msg')) wait_for_assert_equal(len(self.director_window_ready_mock.messages) > 0, True, timeout=self.preloading_grace_time) self.assertEqual(len(self.director_window_ready_mock.messages) > 0, True) self.assertEqual(len(self.director_ready_mock.messages), 1) self.assertEqual(len(self.browser_service_mock_left.messages[0].browsers), 0) self.assertEqual(self.browser_service_mock_center.messages[0].browsers[0].extensions[0].name, 'test_extension1') self.assertEqual(self.browser_service_mock_center.messages[0].browsers[0].extensions[1].name, 'test_extension2') browsers_on_center = self.get_browsers_thru_service('center') # Two extensions, +ros_window_ready +url_monitor self.assertEqual(len(browsers_on_center.items()[0][1]['extensions']), 4) # cleanup self.director_publisher.publish(self.message_factory._get_message('test_no_browsers_msg')) rospy.sleep(self.message_emission_grace_time)
def test3_chrome_commandline_argument_passing(self): """ 1. emit browser with custom command line args - verify that they've been added to cmdargs """ # 1 self.director_publisher.publish( self.message_factory._get_message( 'test_one_browser_with_custom_cmdargs_msg')) rospy.sleep(self.message_emission_grace_time) self.assertEqual(len(self.director_window_ready_mock.messages), 0) self.assertEqual(len(self.director_ready_mock.messages), 0) self.assertEqual(len(self.director_scene_mock.messages), 1) self.assertEqual( self.browser_service_mock_center.messages[0].browsers[0]. command_line_args[0].argument, "--disable-out-of-process-pac") self.assertEqual( self.browser_service_mock_center.messages[0].browsers[0]. command_line_args[1].argument, "--enable-benchmarking") self.assertEqual( self.browser_service_mock_center.messages[0].browsers[0]. command_line_args[2].argument, "--enable-crash-reporter") self.assertEqual( len(self.browser_service_mock_left.messages[0].browsers), 0) wait_for_assert_equal( len(self.get_browsers_thru_service('center').items()), 1, self.preloading_grace_time) browsers_on_center = self.get_browsers_thru_service('center') self.assertEqual( '--disable-out-of-process-pac' in browsers_on_center.items()[0][1]['command_line_args'], True) self.assertEqual( '--enable-benchmarking' in browsers_on_center.items()[0][1]['command_line_args'], True) self.assertEqual( '--enable-crash-reporter' in browsers_on_center.items()[0][1]['command_line_args'], True)
def test8_adhoc_browser_preloading_mix(self): """ 1. emit two browsers on one viewport - one with preloading - the other without preloading - verify readiness and service 2. emit the same message again - non-preloaded browser needs to stay and preloaded browser needs to get re-created 3. emit the same message again but with different slug - non-preloaded browser should stay, preloaded should get re-created TODO(wz): 4. emit non-preloaded message with different slug and make usual asserts 5. emit two browsers - one with preloading - the other without preloading - verify readiness and service 6. emit non-preloaded message with identical slug and make usual asserts - P - preloaded - NP - preloaded - P NP - P NP - P + NP (alt slug) - P + NP (alt slug) - NP + NP - NP + NP - NP + NP (alt slug) - NP + NP (alg slug) """ # 1 self.director_publisher.publish( self.message_factory._get_message( 'test_two_browsers_with_preloading_mix_msg')) rospy.sleep(self.message_emission_grace_time) wait_for_assert_equal(len(self.director_ready_mock.messages), 1, self.preloading_grace_time + 15) self.assertEqual(len(self.director_ready_mock.messages), 1) browsers_on_center = self.get_browsers_thru_service('center') self.assertEqual(len(browsers_on_center), 2) extensions_on_first_browser = browsers_on_center.items()[0][1].get( 'extensions', None) extensions_on_second_browser = browsers_on_center.items()[1][1].get( 'extensions', None) if extensions_on_first_browser and 'ros_window_ready' in ' '.join( browsers_on_center.items()[0][1]['extensions']): preloaded_browser_timestamp = browsers_on_center.items( )[0][1]['timestamp'] non_preloaded_browser_timestamp = browsers_on_center.items( )[1][1]['timestamp'] elif extensions_on_second_browser and 'ros_window_ready' in ' '.join( browsers_on_center.items()[1][1]['extensions']): preloaded_browser_timestamp = browsers_on_center.items( )[1][1]['timestamp'] non_preloaded_browser_timestamp = browsers_on_center.items( )[0][1]['timestamp'] # 2 self.director_publisher.publish( self.message_factory._get_message( 'test_two_browsers_with_preloading_mix_msg')) rospy.sleep(self.message_emission_grace_time) wait_for_assert_equal(len(self.director_ready_mock.messages), 2, self.preloading_grace_time + 15) self.assertEqual(len(self.director_ready_mock.messages), 2) browsers_on_center = self.get_browsers_thru_service('center') self.assertEqual(len(browsers_on_center), 2) extensions_on_first_browser = browsers_on_center.items()[0][1].get( 'extensions', None) extensions_on_second_browser = browsers_on_center.items()[1][1].get( 'extensions', None) if extensions_on_first_browser and 'ros_window_ready' in ' '.join( browsers_on_center.items()[0][1]['extensions']): preloaded_browser_timestamp2 = browsers_on_center.items( )[0][1]['timestamp'] non_preloaded_browser_timestamp2 = browsers_on_center.items( )[1][1]['timestamp'] elif extensions_on_second_browser and 'ros_window_ready' in ' '.join( browsers_on_center.items()[1][1]['extensions']): preloaded_browser_timestamp2 = browsers_on_center.items( )[1][1]['timestamp'] non_preloaded_browser_timestamp2 = browsers_on_center.items( )[0][1]['timestamp'] self.assertNotEqual(preloaded_browser_timestamp2, preloaded_browser_timestamp) self.assertEqual(non_preloaded_browser_timestamp2, non_preloaded_browser_timestamp) # 3 self.director_publisher.publish( self.message_factory._get_message( 'test_two_browsers_with_preloading_mix_alt_slug_msg')) rospy.sleep(self.message_emission_grace_time) wait_for_assert_equal(len(self.director_ready_mock.messages), 3, self.preloading_grace_time + 15) self.assertEqual(len(self.director_ready_mock.messages), 3) browsers_on_center = self.get_browsers_thru_service('center') extensions_on_first_browser = browsers_on_center.items()[0][1].get( 'extensions', None) extensions_on_second_browser = browsers_on_center.items()[1][1].get( 'extensions', None) if extensions_on_first_browser and 'ros_window_ready' in ' '.join( browsers_on_center.items()[0][1]['extensions']): preloaded_browser_timestamp3 = browsers_on_center.items( )[0][1]['timestamp'] non_preloaded_browser_timestamp3 = browsers_on_center.items( )[1][1]['timestamp'] elif extensions_on_second_browser and 'ros_window_ready' in ' '.join( browsers_on_center.items()[1][1]['extensions']): preloaded_browser_timestamp3 = browsers_on_center.items( )[1][1]['timestamp'] non_preloaded_browser_timestamp3 = browsers_on_center.items( )[0][1]['timestamp'] self.assertNotEqual(preloaded_browser_timestamp2, preloaded_browser_timestamp3) self.assertEqual(non_preloaded_browser_timestamp2, non_preloaded_browser_timestamp3)
def test7_adhoc_browser_preloading(self): """ 1.preloading: a) emit message with preloading - verify readiness message came, make service assert b) emit the same message with preloading again - verify readiness message came, make service assert and confirm that browsers were re-created c) emit the same message but with different slug - verify the same as above d) emit non-preloaded message with different slug and make usual asserts """ # 1a self.director_publisher.publish( self.message_factory._get_message( 'test_one_browser_with_preloading_msg')) rospy.sleep(self.message_emission_grace_time) wait_for_assert_equal( len(self.director_window_ready_mock.messages) > 0, True, self.preloading_grace_time) self.assertEqual( len(self.director_window_ready_mock.messages) > 0, True) self.assertEqual(len(self.director_scene_mock.messages), 1) self.assertEqual(len(self.director_ready_mock.messages), 1) browsers_on_center = self.get_browsers_thru_service('center') browser_timestamp = browsers_on_center.items()[0][1]['timestamp'] # 1b self.director_publisher.publish( self.message_factory._get_message( 'test_one_browser_with_preloading_msg')) rospy.sleep(self.message_emission_grace_time) wait_for_assert_equal(len(self.director_ready_mock.messages), 2, self.preloading_grace_time) self.assertEqual(len(self.director_ready_mock.messages), 2) browsers_on_center = self.get_browsers_thru_service('center') self.assertEqual(len(browsers_on_center), 1) browser_timestamp2 = browsers_on_center.items()[0][1]['timestamp'] self.assertNotEqual(browser_timestamp, browser_timestamp2) self.assertGreater(browser_timestamp2, browser_timestamp) # 1c self.director_publisher.publish( self.message_factory._get_message( 'test_one_browser_with_preloading_alt_slug_msg')) rospy.sleep(self.message_emission_grace_time) wait_for_assert_equal(len(self.director_ready_mock.messages), 3, self.preloading_grace_time) self.assertEqual(len(self.director_ready_mock.messages), 3) browsers_on_center = self.get_browsers_thru_service('center') self.assertEqual(len(browsers_on_center), 1) browser_timestamp3 = browsers_on_center.items()[0][1]['timestamp'] self.assertNotEqual(browser_timestamp2, browser_timestamp3) self.assertGreater(browser_timestamp3, browser_timestamp2) # 1d self.director_publisher.publish( self.message_factory._get_message( 'test_one_browser_on_center_msg')) rospy.sleep(self.message_emission_grace_time) wait_for_assert_equal(len(self.director_ready_mock.messages), 3, self.preloading_grace_time) self.assertEqual(len(self.director_ready_mock.messages), 3) browsers_on_center = self.get_browsers_thru_service('center') self.assertEqual(len(browsers_on_center), 1) browser_timestamp4 = browsers_on_center.items()[0][1]['timestamp'] self.assertNotEqual(browser_timestamp3, browser_timestamp4) self.assertGreater(browser_timestamp4, browser_timestamp3)
def test6_chrome_persistence(self): """ 1. emit one browser without preloading - make service assert 2. emit the same message again and verify that they havent been updated 3. emit same message but with a different slug - verify that they havent been touched """ # 1 self.director_publisher.publish( self.message_factory._get_message( 'test_one_browser_on_center_msg')) rospy.sleep(self.message_emission_grace_time) wait_for_assert_equal(len(self.director_scene_mock.messages), 1, self.preloading_grace_time) # no director window ready should be published self.assertEqual(len(self.director_window_ready_mock.messages), 0) self.assertEqual(len(self.director_ready_mock.messages), 0) self.assertEqual( self.browser_service_mock_center.messages[0].browsers[0].id, 'gzJERcJ') browsers_on_center = self.get_browsers_thru_service('center') # self.assertEqual(browsers_on_center, 'asd') browser_timestamp_before = browsers_on_center['gzJERcJ']['timestamp'] self.assertEqual(browsers_on_center['gzJERcJ']['uid'], 'gzJERcJ') # 2 self.director_publisher.publish( self.message_factory._get_message( 'test_one_browser_on_center_msg')) rospy.sleep(self.message_emission_grace_time) wait_for_assert_equal(len(self.director_scene_mock.messages), 2, self.preloading_grace_time) self.assertEqual(len(self.director_window_ready_mock.messages), 0) self.assertEqual(len(self.director_ready_mock.messages), 0) self.assertEqual( self.browser_service_mock_center.messages[0].browsers[0].id, 'gzJERcJ') self.assertEqual( self.browser_service_mock_center.messages[1].browsers[0].id, 'gzJERcJ') browsers_on_center = self.get_browsers_thru_service('center') self.assertEqual(len(browsers_on_center.items()), 1) browser_timestamp_after = browsers_on_center.items()[0][1]['timestamp'] self.assertEqual(browsers_on_center['gzJERcJ']['uid'], 'gzJERcJ') self.assertEqual( browser_timestamp_before, browser_timestamp_after, "Emitting same message with identical browser updated the browser instance" ) # 3 self.director_publisher.publish( self.message_factory._get_message( 'test_one_browser_on_center_alt_slug_msg')) rospy.sleep(self.message_emission_grace_time) self.assertEqual(len(self.director_ready_mock.messages), 0) self.assertEqual(len(self.director_scene_mock.messages), 3) self.assertEqual( len(self.browser_service_mock_left.messages[0].browsers), 0) self.assertEqual( self.browser_service_mock_center.messages[0].browsers[0].id, 'gzJERcJ') self.assertEqual( self.browser_service_mock_center.messages[1].browsers[0].id, 'gzJERcJ') self.assertEqual( self.browser_service_mock_center.messages[2].browsers[0].id, 'gzJERcJ') browsers_on_center = self.get_browsers_thru_service('center') self.assertEqual(len(browsers_on_center.items()), 1) self.assertEqual(browsers_on_center['gzJERcJ']['uid'], 'gzJERcJ') self.assertEqual( browser_timestamp_before, browser_timestamp_after, "Emitting same message with identical browser updated the browser instance" ) browser_timestamp_even_after = browsers_on_center.items( )[0][1]['timestamp'] self.assertEqual( browser_timestamp_before, browser_timestamp_even_after, "Emitting same message with identical browser but different scene slug updated the browser instance" )
def test8_adhoc_browser_preloading_mix(self): """ 1. emit two browsers on one viewport - one with preloading - the other without preloading - verify readiness and service 2. emit the same message again - non-preloaded browser needs to stay and preloaded browser needs to get re-created 3. emit the same message again but with different slug - non-preloaded browser should stay, preloaded should get re-created TODO(wz): 4. emit non-preloaded message with different slug and make usual asserts 5. emit two browsers - one with preloading - the other without preloading - verify readiness and service 6. emit non-preloaded message with identical slug and make usual asserts - P - preloaded - NP - preloaded - P NP - P NP - P + NP (alt slug) - P + NP (alt slug) - NP + NP - NP + NP - NP + NP (alt slug) - NP + NP (alg slug) """ # 1 self.director_publisher.publish(self.message_factory._get_message('test_two_browsers_with_preloading_mix_msg')) rospy.sleep(self.message_emission_grace_time) wait_for_assert_equal(len(self.director_ready_mock.messages), 1, self.preloading_grace_time + 15) self.assertEqual(len(self.director_ready_mock.messages), 1) browsers_on_center = self.get_browsers_thru_service('center') self.assertEqual(len(browsers_on_center), 2) extensions_on_first_browser = browsers_on_center.items()[0][1].get('extensions', None) extensions_on_second_browser = browsers_on_center.items()[1][1].get('extensions', None) if extensions_on_first_browser and 'ros_window_ready' in ' '.join(browsers_on_center.items()[0][1]['extensions']): preloaded_browser_timestamp = browsers_on_center.items()[0][1]['timestamp'] non_preloaded_browser_timestamp = browsers_on_center.items()[1][1]['timestamp'] elif extensions_on_second_browser and 'ros_window_ready' in ' '.join(browsers_on_center.items()[1][1]['extensions']): preloaded_browser_timestamp = browsers_on_center.items()[1][1]['timestamp'] non_preloaded_browser_timestamp = browsers_on_center.items()[0][1]['timestamp'] # 2 self.director_publisher.publish(self.message_factory._get_message('test_two_browsers_with_preloading_mix_msg')) rospy.sleep(self.message_emission_grace_time) wait_for_assert_equal(len(self.director_ready_mock.messages), 2, self.preloading_grace_time + 15) self.assertEqual(len(self.director_ready_mock.messages), 2) browsers_on_center = self.get_browsers_thru_service('center') self.assertEqual(len(browsers_on_center), 2) extensions_on_first_browser = browsers_on_center.items()[0][1].get('extensions', None) extensions_on_second_browser = browsers_on_center.items()[1][1].get('extensions', None) if extensions_on_first_browser and 'ros_window_ready' in ' '.join(browsers_on_center.items()[0][1]['extensions']): preloaded_browser_timestamp2 = browsers_on_center.items()[0][1]['timestamp'] non_preloaded_browser_timestamp2 = browsers_on_center.items()[1][1]['timestamp'] elif extensions_on_second_browser and 'ros_window_ready' in ' '.join(browsers_on_center.items()[1][1]['extensions']): preloaded_browser_timestamp2 = browsers_on_center.items()[1][1]['timestamp'] non_preloaded_browser_timestamp2 = browsers_on_center.items()[0][1]['timestamp'] self.assertNotEqual(preloaded_browser_timestamp2, preloaded_browser_timestamp) self.assertEqual(non_preloaded_browser_timestamp2, non_preloaded_browser_timestamp) # 3 self.director_publisher.publish(self.message_factory._get_message('test_two_browsers_with_preloading_mix_alt_slug_msg')) rospy.sleep(self.message_emission_grace_time) wait_for_assert_equal(len(self.director_ready_mock.messages), 3, self.preloading_grace_time + 15) self.assertEqual(len(self.director_ready_mock.messages), 3) browsers_on_center = self.get_browsers_thru_service('center') extensions_on_first_browser = browsers_on_center.items()[0][1].get('extensions', None) extensions_on_second_browser = browsers_on_center.items()[1][1].get('extensions', None) if extensions_on_first_browser and 'ros_window_ready' in ' '.join(browsers_on_center.items()[0][1]['extensions']): preloaded_browser_timestamp3 = browsers_on_center.items()[0][1]['timestamp'] non_preloaded_browser_timestamp3 = browsers_on_center.items()[1][1]['timestamp'] elif extensions_on_second_browser and 'ros_window_ready' in ' '.join(browsers_on_center.items()[1][1]['extensions']): preloaded_browser_timestamp3 = browsers_on_center.items()[1][1]['timestamp'] non_preloaded_browser_timestamp3 = browsers_on_center.items()[0][1]['timestamp'] self.assertNotEqual(preloaded_browser_timestamp2, preloaded_browser_timestamp3) self.assertEqual(non_preloaded_browser_timestamp2, non_preloaded_browser_timestamp3)