diff --git a/core/lib/Drupal/Core/Cache/Context/AccountPermissionsCacheContext.php b/core/lib/Drupal/Core/Cache/Context/AccountPermissionsCacheContext.php
index 01e6ce8..7986ae7 100644
--- a/core/lib/Drupal/Core/Cache/Context/AccountPermissionsCacheContext.php
+++ b/core/lib/Drupal/Core/Cache/Context/AccountPermissionsCacheContext.php
@@ -51,4 +51,15 @@ public function getContext() {
     return 'ph.' . $this->permissionsHashGenerator->generate($this->user);
   }
 
+  /**
+  * {@inheritdoc}
+  */
+  public function getCacheTags() {
+    $tags = [];
+    foreach ($this->user->getRoles() as $role) {
+      $tags[] = "config:user.role.$role";
+    }
+    return $tags;
+  }
+
 }
diff --git a/core/lib/Drupal/Core/Cache/Context/CacheContextsManager.php b/core/lib/Drupal/Core/Cache/Context/CacheContextsManager.php
index 27b012a..b174d78 100644
--- a/core/lib/Drupal/Core/Cache/Context/CacheContextsManager.php
+++ b/core/lib/Drupal/Core/Cache/Context/CacheContextsManager.php
@@ -8,6 +8,7 @@
 namespace Drupal\Core\Cache\Context;
 
 use Drupal\Component\Utility\SafeMarkup;
+use Drupal\Core\Cache\CacheableMetadata;
 use Symfony\Component\DependencyInjection\ContainerInterface;
 
 /**
@@ -88,7 +89,7 @@ public function getLabels($include_calculated_cache_contexts = FALSE) {
   }
 
   /**
-   * Converts cache context tokens to cache keys.
+   * Converts cache context tokens to cache keys and gets their cacheable metadata.
    *
    * A cache context token is either:
    * - a cache context ID (if the service ID is 'cache_context.foo', then 'foo'
@@ -99,12 +100,23 @@ public function getLabels($include_calculated_cache_contexts = FALSE) {
    * @param string[] $context_tokens
    *   An array of cache context tokens.
    *
-   * @return string[]
-   *   The array of corresponding cache keys.
+   * @return mixed[]
+   *   An array containing two items; contexts and cacheable_metadata.
    *
    * @throws \InvalidArgumentException
    */
   public function convertTokensToKeys(array $context_tokens) {
+    $cacheable_metadata = new CacheableMetadata();
+
+    // Iterate through cache contexts and get their cacheable metadata.
+    foreach (static::parseTokens($context_tokens) as $context_token) {
+      list($context_id, $parameter) = $context_token;
+      $context = $this->getService($context_id);
+      if ($context instanceof CacheableCacheContextInterface || $context instanceof CacheableCalculatedCacheContextInterface) {
+        $cacheable_metadata = $cacheable_metadata->merge(CacheableMetadata::createFromObject($context->getCacheableMetadata()));
+      }
+    }
+
     $context_tokens = $this->optimizeTokens($context_tokens);
     sort($context_tokens);
     $keys = [];
@@ -115,7 +127,13 @@ public function convertTokensToKeys(array $context_tokens) {
       }
       $keys[] = $this->getService($context_id)->getContext($parameter);
     }
-    return $keys;
+
+    $values = [
+      'contexts' => $keys,
+      'cacheable_metadata' => $cacheable_metadata,
+    ];
+
+    return $values;
   }
 
   /**
diff --git a/core/lib/Drupal/Core/Cache/Context/CacheableCacheContextInterface.php b/core/lib/Drupal/Core/Cache/Context/CacheableCacheContextInterface.php
new file mode 100644
index 0000000..c3fd648
--- /dev/null
+++ b/core/lib/Drupal/Core/Cache/Context/CacheableCacheContextInterface.php
@@ -0,0 +1,22 @@
+<?php
+
+/**
+ * @file
+ * Contains \Drupal\Core\Cache\Context\CacheableCacheContextInterface.
+ */
+
+namespace Drupal\Core\Cache\Context;
+
+use Drupal\Core\Cache\CacheableDependencyInterface;
+
+interface CacheableCacheContextInterface extends CacheContextInterface, CacheableDependencyInterface {
+
+  /**
+   * Gets the cacheable metadata for the context based on the parameter value.
+   *
+   * @return \Drupal\Core\Cache\CacheableDependencyInterface
+   *   A cacheable dependency interface implementing object, e.g. CacheableMetadata
+   */
+  public function getCacheableMetadata();
+
+}
\ No newline at end of file
diff --git a/core/lib/Drupal/Core/Cache/Context/CacheableCalculatedCacheContextInterface.php b/core/lib/Drupal/Core/Cache/Context/CacheableCalculatedCacheContextInterface.php
new file mode 100644
index 0000000..2507607
--- /dev/null
+++ b/core/lib/Drupal/Core/Cache/Context/CacheableCalculatedCacheContextInterface.php
@@ -0,0 +1,25 @@
+<?php
+
+/**
+ * @file
+ * Contains \Drupal\Core\Cache\Context\CacheableCacheContextInterface.
+ */
+
+namespace Drupal\Core\Cache\Context;
+
+use Drupal\Core\Cache\CacheableDependencyInterface;
+
+interface CacheableCalculatedCacheContextInterface extends CalculatedCacheContextInterface {
+
+  /**
+   * Gets the cacheable metadata for the context based on the parameter value.
+   *
+   * @param mixed $parameter
+   *   The parameter to get context values for.
+   *
+   * @return \Drupal\Core\Cache\CacheableDependencyInterface
+   *   A cacheable dependency interface implementing object, e.g. CacheableMetadata
+   */
+  public function getCacheableMetadata($parameter = NULL);
+
+}
\ No newline at end of file
diff --git a/core/lib/Drupal/Core/Cache/Context/UserCacheContext.php b/core/lib/Drupal/Core/Cache/Context/UserCacheContext.php
index d7b8051..3a70858 100644
--- a/core/lib/Drupal/Core/Cache/Context/UserCacheContext.php
+++ b/core/lib/Drupal/Core/Cache/Context/UserCacheContext.php
@@ -7,6 +7,7 @@
 
 namespace Drupal\Core\Cache\Context;
 
+use Drupal\Core\Cache\Cache;
 use Drupal\Core\Session\AccountInterface;
 
 /**
@@ -14,7 +15,7 @@
  *
  * Cache context ID: 'user'.
  */
-class UserCacheContext implements CacheContextInterface {
+class UserCacheContext implements CacheableCacheContextInterface {
 
   /**
    * Constructs a new UserCacheContext service.
@@ -40,4 +41,32 @@ public function getContext() {
     return "u." . $this->user->id();
   }
 
+  /**
+   * {@inheritdoc}
+   */
+  public function getCacheContexts() {
+    return [];
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function getCacheTags() {
+    return [];
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function getCacheMaxAge() {
+    return Cache::PERMANENT;
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function getCacheableMetadata() {
+    return $this;
+  }
+
 }
diff --git a/core/lib/Drupal/Core/Render/RenderCache.php b/core/lib/Drupal/Core/Render/RenderCache.php
index 1a8339b..6e29f2b 100644
--- a/core/lib/Drupal/Core/Render/RenderCache.php
+++ b/core/lib/Drupal/Core/Render/RenderCache.php
@@ -295,7 +295,7 @@ protected function maxAgeToExpire($max_age) {
    * @return string
    *   The cache ID string, or FALSE if the element may not be cached.
    */
-  protected function createCacheID(array $elements) {
+  protected function createCacheID(array &$elements) {
     // If the maximum age is zero, then caching is effectively prohibited.
     if (isset($elements['#cache']['max-age']) && $elements['#cache']['max-age'] === 0) {
       return FALSE;
@@ -305,7 +305,10 @@ protected function createCacheID(array $elements) {
       $cid_parts = $elements['#cache']['keys'];
       if (!empty($elements['#cache']['contexts'])) {
         $contexts = $this->cacheContextsManager->convertTokensToKeys($elements['#cache']['contexts']);
-        $cid_parts = array_merge($cid_parts, $contexts);
+        $cid_parts = array_merge($cid_parts, $contexts['contexts']);
+        CacheableMetadata::createFromRenderArray($elements)
+          ->merge($contexts['cacheable_metadata'])
+          ->applyTo($elements);
       }
       return implode(':', $cid_parts);
     }
diff --git a/core/modules/comment/src/Tests/CommentCacheTagsTest.php b/core/modules/comment/src/Tests/CommentCacheTagsTest.php
index 5226434..7bb55a5 100644
--- a/core/modules/comment/src/Tests/CommentCacheTagsTest.php
+++ b/core/modules/comment/src/Tests/CommentCacheTagsTest.php
@@ -102,6 +102,7 @@ protected function getAdditionalCacheTagsForEntity(EntityInterface $entity) {
     /** @var \Drupal\comment\CommentInterface $entity */
     return array(
       'config:filter.format.plain_text',
+      'config:user.role.anonymous',
       'user:' . $entity->getOwnerId(),
       'user_view',
     );
diff --git a/core/modules/comment/src/Tests/CommentDefaultFormatterCacheTagsTest.php b/core/modules/comment/src/Tests/CommentDefaultFormatterCacheTagsTest.php
index 8e7bf27..7107981 100644
--- a/core/modules/comment/src/Tests/CommentDefaultFormatterCacheTagsTest.php
+++ b/core/modules/comment/src/Tests/CommentDefaultFormatterCacheTagsTest.php
@@ -7,6 +7,7 @@
 
 namespace Drupal\comment\Tests;
 
+use Drupal\Core\Cache\Cache;
 use Drupal\Core\Session\UserSession;
 use Drupal\comment\CommentInterface;
 use Drupal\system\Tests\Entity\EntityUnitTestBase;
@@ -69,7 +70,8 @@ public function testCacheTags() {
       ->getViewBuilder('entity_test')
       ->view($commented_entity);
     $renderer->renderRoot($build);
-    $expected_cache_tags = array(
+    $cache_context_tags = \Drupal::service('cache_contexts_manager')->convertTokensToKeys($build['#cache']['contexts'])['cacheable_metadata']->getCacheTags();
+    $expected_cache_tags = Cache::mergeTags($cache_context_tags, [
       'entity_test_view',
       'entity_test:'  . $commented_entity->id(),
       'comment_list',
@@ -78,9 +80,9 @@ public function testCacheTags() {
       'config:field.field.entity_test.entity_test.comment',
       'config:field.storage.comment.comment_body',
       'config:user.settings',
-    );
+    ]);
     sort($expected_cache_tags);
-    $this->assertEqual($build['#cache']['tags'], $expected_cache_tags, 'The test entity has the expected cache tags before it has comments.');
+    $this->assertEqual($build['#cache']['tags'], $expected_cache_tags);
 
     // Create a comment on that entity. Comment loading requires that the uid
     // also exists in the {users} table.
@@ -111,7 +113,8 @@ public function testCacheTags() {
       ->getViewBuilder('entity_test')
       ->view($commented_entity);
     $renderer->renderRoot($build);
-    $expected_cache_tags = array(
+    $cache_context_tags = \Drupal::service('cache_contexts_manager')->convertTokensToKeys($build['#cache']['contexts'])['cacheable_metadata']->getCacheTags();
+    $expected_cache_tags = Cache::mergeTags($cache_context_tags, [
       'entity_test_view',
       'entity_test:' . $commented_entity->id(),
       'comment_list',
@@ -125,9 +128,9 @@ public function testCacheTags() {
       'config:field.field.entity_test.entity_test.comment',
       'config:field.storage.comment.comment_body',
       'config:user.settings',
-    );
+    ]);
     sort($expected_cache_tags);
-    $this->assertEqual($build['#cache']['tags'], $expected_cache_tags, 'The test entity has the expected cache tags when it has comments.');
+    $this->assertEqual($build['#cache']['tags'], $expected_cache_tags);
   }
 
 }
diff --git a/core/modules/comment/src/Tests/CommentRssTest.php b/core/modules/comment/src/Tests/CommentRssTest.php
index b82da48..5821c59 100644
--- a/core/modules/comment/src/Tests/CommentRssTest.php
+++ b/core/modules/comment/src/Tests/CommentRssTest.php
@@ -8,6 +8,7 @@
 namespace Drupal\comment\Tests;
 
 use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface;
+use Drupal\Core\Cache\Cache;
 use Drupal\Core\Entity\Entity\EntityViewDisplay;
 use Drupal\system\Tests\Cache\AssertPageCacheContextsAndTagsTrait;
 
@@ -52,16 +53,22 @@ function testCommentRss() {
     $this->postComment($this->node, $this->randomMachineName(), $this->randomMachineName());
     $this->drupalGet('rss.xml');
 
-    $this->assertCacheTags([
-      'config:views.view.frontpage', 'node:1', 'node_list', 'node_view', 'user:3',
-    ]);
-    $this->assertCacheContexts([
+    $cache_contexts = [
       'languages:language_interface',
       'theme',
       'user.node_grants:view',
       'user.permissions',
       'timezone',
-    ]);
+    ];
+    $this->assertCacheContexts($cache_contexts);
+
+    $cache_context_tags = \Drupal::service('cache_contexts_manager')->convertTokensToKeys($cache_contexts)['cacheable_metadata']->getCacheTags();
+    $this->assertCacheTags(Cache::mergeTags($cache_context_tags, [
+      'config:views.view.frontpage',
+      'node:1', 'node_list',
+      'node_view',
+      'user:3',
+    ]));
 
     $raw = '<comments>' . $this->node->url('canonical', array('fragment' => 'comments', 'absolute' => TRUE)) . '</comments>';
     $this->assertRaw($raw, 'Comments as part of RSS feed.');
diff --git a/core/modules/field/src/Tests/EntityReference/EntityReferenceFormatterTest.php b/core/modules/field/src/Tests/EntityReference/EntityReferenceFormatterTest.php
index 6f04ba2..9ac89b5 100644
--- a/core/modules/field/src/Tests/EntityReference/EntityReferenceFormatterTest.php
+++ b/core/modules/field/src/Tests/EntityReference/EntityReferenceFormatterTest.php
@@ -203,7 +203,8 @@ public function testEntityFormatter() {
     $expected_cache_tags = Cache::mergeTags(
       \Drupal::entityManager()->getViewBuilder($this->entityType)->getCacheTags(),
       $this->referencedEntity->getCacheTags(),
-      FilterFormat::load('full_html')->getCacheTags()
+      FilterFormat::load('full_html')->getCacheTags(),
+      ['config:user.role.anonymous']
     );
     $this->assertEqual($build[0]['#cache']['tags'], $expected_cache_tags, format_string('The @formatter formatter has the expected cache tags.', array('@formatter' => $formatter)));
 
diff --git a/core/modules/node/src/Tests/Views/FrontPageTest.php b/core/modules/node/src/Tests/Views/FrontPageTest.php
index b3ab9c9..cb2e0ab 100644
--- a/core/modules/node/src/Tests/Views/FrontPageTest.php
+++ b/core/modules/node/src/Tests/Views/FrontPageTest.php
@@ -251,6 +251,8 @@ protected function assertFrontPageViewCacheTags($do_assert_views_caches) {
       'url.query_args.pagers:0',
     ];
 
+    $cache_context_tags = \Drupal::service('cache_contexts_manager')->convertTokensToKeys($cache_contexts)['cacheable_metadata']->getCacheTags();
+
     // Test before there are any nodes.
     $empty_node_listing_cache_tags = [
       'config:views.view.frontpage',
@@ -260,12 +262,12 @@ protected function assertFrontPageViewCacheTags($do_assert_views_caches) {
       $view,
       $empty_node_listing_cache_tags,
       $do_assert_views_caches,
-      $empty_node_listing_cache_tags
+      Cache::mergeTags($empty_node_listing_cache_tags, $cache_context_tags)
     );
     $this->assertPageCacheContextsAndTags(
       Url::fromRoute('view.frontpage.page_1'),
       $cache_contexts,
-      Cache::mergeTags($empty_node_listing_cache_tags, ['rendered', 'config:user.role.anonymous'])
+      Cache::mergeTags($empty_node_listing_cache_tags, $cache_context_tags, ['rendered', 'config:user.role.anonymous'])
     );
 
     // Create some nodes on the frontpage view. Add more than 10 nodes in order
@@ -307,12 +309,17 @@ protected function assertFrontPageViewCacheTags($do_assert_views_caches) {
       'node:14',
       'node:15',
     ];
-    $first_page_output_cache_tags = Cache::mergeTags($first_page_result_cache_tags, [
-      'config:filter.format.plain_text',
-      'node_view',
-      'user_view',
-      'user:0',
-    ]);
+    $cache_context_tags = \Drupal::service('cache_contexts_manager')->convertTokensToKeys($cache_contexts)['cacheable_metadata']->getCacheTags();
+    $first_page_output_cache_tags = Cache::mergeTags(
+      $first_page_result_cache_tags,
+      $cache_context_tags,
+      [
+        'config:filter.format.plain_text',
+        'node_view',
+        'user_view',
+        'user:0',
+      ]
+    );
     $view->setDisplay('page_1');
     $view->setCurrentPage(0);
     $this->assertViewsCacheTags(
diff --git a/core/modules/system/src/Tests/Entity/EntityCacheTagsTestBase.php b/core/modules/system/src/Tests/Entity/EntityCacheTagsTestBase.php
index 0b365cb..5e7219e 100644
--- a/core/modules/system/src/Tests/Entity/EntityCacheTagsTestBase.php
+++ b/core/modules/system/src/Tests/Entity/EntityCacheTagsTestBase.php
@@ -349,6 +349,9 @@ public function testReferencedEntity() {
         ->getCacheTags();
     }
 
+    $context_metadata = \Drupal::service('cache_contexts_manager')->convertTokensToKeys($entity_cache_contexts)['cacheable_metadata'];
+    $cache_context_tags = $context_metadata->getCacheTags();
+
     // Generate the cache tags for the (non) referencing entities.
     $referencing_entity_cache_tags = Cache::mergeTags(
       $this->referencingEntity->getCacheTags(),
@@ -357,6 +360,7 @@ public function testReferencedEntity() {
       $this->entity->getCacheTags(),
       $this->getAdditionalCacheTagsForEntity($this->entity),
       $view_cache_tag,
+      $cache_context_tags,
       ['rendered']
     );
     $non_referencing_entity_cache_tags = Cache::mergeTags(
@@ -389,7 +393,10 @@ public function testReferencedEntity() {
     $access_cache_contexts = $this->getAccessCacheContextsForEntity($this->entity);
     $redirected_cid = NULL;
     if (count($access_cache_contexts)) {
-      $redirected_cid = $this->createCacheId($cache_keys, Cache::mergeContexts($entity_cache_contexts, $this->getAdditionalCacheContextsForEntity($this->referencingEntity), $access_cache_contexts));
+      $cache_contexts = Cache::mergeContexts($entity_cache_contexts, $this->getAdditionalCacheContextsForEntity($this->referencingEntity), $access_cache_contexts);
+      $redirected_cid = $this->createCacheId($cache_keys, $cache_contexts);
+      $context_metadata = \Drupal::service('cache_contexts_manager')->convertTokensToKeys($cache_contexts)['cacheable_metadata'];
+      $referencing_entity_cache_tags = Cache::mergeTags($referencing_entity_cache_tags, $context_metadata->getCacheTags());
     }
     $this->verifyRenderCache($cid, $referencing_entity_cache_tags, $redirected_cid);
 
@@ -653,7 +660,7 @@ protected function createCacheId(array $keys, array $contexts) {
     $cid_parts = $keys;
 
     $contexts = \Drupal::service('cache_contexts_manager')->convertTokensToKeys($contexts);
-    $cid_parts = array_merge($cid_parts, $contexts);
+    $cid_parts = array_merge($cid_parts, $contexts['contexts']);
 
     return implode(':', $cid_parts);
   }
diff --git a/core/modules/system/src/Tests/Entity/EntityViewBuilderTest.php b/core/modules/system/src/Tests/Entity/EntityViewBuilderTest.php
index a7aa63d..874526a 100644
--- a/core/modules/system/src/Tests/Entity/EntityViewBuilderTest.php
+++ b/core/modules/system/src/Tests/Entity/EntityViewBuilderTest.php
@@ -65,7 +65,7 @@ public function testEntityViewBuilderCache() {
     // Get a fully built entity view render array.
     $entity_test->save();
     $build = $this->container->get('entity.manager')->getViewBuilder('entity_test')->view($entity_test, 'full');
-    $cid_parts = array_merge($build['#cache']['keys'], $cache_contexts_manager->convertTokensToKeys(['languages:' . LanguageInterface::TYPE_INTERFACE, 'theme']));
+    $cid_parts = array_merge($build['#cache']['keys'], $cache_contexts_manager->convertTokensToKeys(['languages:' . LanguageInterface::TYPE_INTERFACE, 'theme'])['contexts']);
     $cid = implode(':', $cid_parts);
     $bin = $build['#cache']['bin'];
 
@@ -117,7 +117,7 @@ public function testEntityViewBuilderCacheWithReferences() {
 
     // Get a fully built entity view render array for the referenced entity.
     $build = $this->container->get('entity.manager')->getViewBuilder('entity_test')->view($entity_test_reference, 'full');
-    $cid_parts = array_merge($build['#cache']['keys'], $cache_contexts_manager->convertTokensToKeys(['languages:' . LanguageInterface::TYPE_INTERFACE, 'theme']));
+    $cid_parts = array_merge($build['#cache']['keys'], $cache_contexts_manager->convertTokensToKeys(['languages:' . LanguageInterface::TYPE_INTERFACE, 'theme'])['contexts']);
     $cid_reference = implode(':', $cid_parts);
     $bin_reference = $build['#cache']['bin'];
 
@@ -136,7 +136,7 @@ public function testEntityViewBuilderCacheWithReferences() {
 
     // Get a fully built entity view render array.
     $build = $this->container->get('entity.manager')->getViewBuilder('entity_test')->view($entity_test, 'full');
-    $cid_parts = array_merge($build['#cache']['keys'], $cache_contexts_manager->convertTokensToKeys(['languages:' . LanguageInterface::TYPE_INTERFACE, 'theme']));
+    $cid_parts = array_merge($build['#cache']['keys'], $cache_contexts_manager->convertTokensToKeys(['languages:' . LanguageInterface::TYPE_INTERFACE, 'theme'])['contexts']);
     $cid = implode(':', $cid_parts);
     $bin = $build['#cache']['bin'];
 
diff --git a/core/modules/system/src/Tests/Render/PermissionsCacheContextTest.php b/core/modules/system/src/Tests/Render/PermissionsCacheContextTest.php
new file mode 100644
index 0000000..71d42a6
--- /dev/null
+++ b/core/modules/system/src/Tests/Render/PermissionsCacheContextTest.php
@@ -0,0 +1,78 @@
+<?php
+
+/**
+ * @file
+ * Contains \Drupal\system\Tests\Render\PermissionsCacheContextTest.
+ */
+
+namespace Drupal\system\Tests\Render;
+
+use Drupal\simpletest\KernelTestBase;
+use Drupal\simpletest\UserCreationTrait;
+use Drupal\user\Entity\Role;
+
+/**
+ * Tests the permissions cache context.
+ *
+ * @group Render
+ */
+class PermissionsCacheContextTest extends KernelTestBase {
+
+  use UserCreationTrait;
+
+  /**
+   * Modules to enable.
+   *
+   * @var string[]
+   */
+  public static $modules = ['user', 'system'];
+
+  /**
+   * {@inheritdoc}
+   */
+  protected function setUp() {
+    parent::setUp();
+    $this->installEntitySchema('user');
+    $this->installConfig(['user']);
+    $this->installSchema('system', ['sequences']);
+  }
+
+  /**
+   * Ensures that permission change works with permission and user contexts.
+   */
+  public function testPermissionChange() {
+    $user1 = $this->createUser();
+    $this->assertEqual($user1->id(), 1);
+
+    $authenticated_user = $this->createUser(['administer permissions']);
+    $role = $authenticated_user->getRoles()[1];
+
+    $test_element = [
+      '#cache' => [
+        'keys' => ['test'],
+        'contexts' => ['user', 'user.permissions'],
+      ],
+    ];
+    \Drupal::service('account_switcher')->switchTo($authenticated_user);
+    $element = $test_element;
+    $element['#markup'] = 'content for authenticated users';
+    $output = \Drupal::service('renderer')->renderRoot($element);
+    $this->assertEqual($output, 'content for authenticated users');
+
+    // Verify that the render caching is working.
+    $element = $test_element;
+    $element['#markup'] = 'this should not be visible';
+    $output = \Drupal::service('renderer')->renderRoot($element);
+    $this->assertEqual($output, 'content for authenticated users');
+
+    // Verify that the element is being rendered after permissions have changed.
+    Role::load($role)
+      ->revokePermission('administer permissions')
+      ->save();
+    $element = $test_element;
+    $element['#markup'] = 'this should be visible';
+    $output = \Drupal::service('renderer')->renderRoot($element);
+    $this->assertEqual($output, 'this should be visible');
+  }
+
+}
diff --git a/core/modules/system/tests/modules/pager_test/src/Controller/PagerTestController.php b/core/modules/system/tests/modules/pager_test/src/Controller/PagerTestController.php
index 004603f..399da55 100644
--- a/core/modules/system/tests/modules/pager_test/src/Controller/PagerTestController.php
+++ b/core/modules/system/tests/modules/pager_test/src/Controller/PagerTestController.php
@@ -69,7 +69,7 @@ public function queryParameters() {
    * #pre_render callback for #type => pager that shows the pager cache context.
    */
   public static function showPagerCacheContext(array $pager) {
-    drupal_set_message(\Drupal::service('cache_contexts_manager')->convertTokensToKeys(['url.query_args.pagers:' . $pager['#element']])[0]);
+    drupal_set_message(\Drupal::service('cache_contexts_manager')->convertTokensToKeys(['url.query_args.pagers:' . $pager['#element']])['contexts'][0]);
     return $pager;
   }
 
diff --git a/core/tests/Drupal/Tests/Core/Cache/Context/CacheContextsManagerTest.php b/core/tests/Drupal/Tests/Core/Cache/Context/CacheContextsManagerTest.php
index 99a32b3..3641773 100644
--- a/core/tests/Drupal/Tests/Core/Cache/Context/CacheContextsManagerTest.php
+++ b/core/tests/Drupal/Tests/Core/Cache/Context/CacheContextsManagerTest.php
@@ -95,7 +95,7 @@ public function testConvertTokensToKeys() {
       'baz.cnenzrgreO',
       'bar',
     ];
-    $this->assertEquals($expected, $new_keys);
+    $this->assertEquals($expected, $new_keys['contexts']);
   }
 
   /**
diff --git a/core/tests/Drupal/Tests/Core/Render/RendererTestBase.php b/core/tests/Drupal/Tests/Core/Render/RendererTestBase.php
index 7388c61..b0af10c 100644
--- a/core/tests/Drupal/Tests/Core/Render/RendererTestBase.php
+++ b/core/tests/Drupal/Tests/Core/Render/RendererTestBase.php
@@ -8,6 +8,7 @@
 namespace Drupal\Tests\Core\Render;
 
 use Drupal\Core\Cache\Cache;
+use Drupal\Core\Cache\CacheableMetadata;
 use Drupal\Core\Cache\MemoryBackend;
 use Drupal\Core\Language\LanguageInterface;
 use Drupal\Core\Render\Element;
@@ -124,7 +125,7 @@ protected function setUp() {
               $keys[] = $context_id;
           }
         }
-        return $keys;
+        return ['contexts' => $keys, 'cacheable_metadata' => new CacheableMetadata()];
       });
     $this->renderCache = new RenderCache($this->requestStack, $this->cacheFactory, $this->cacheContextsManager);
     $this->renderer = new Renderer($this->controllerResolver, $this->themeManager, $this->elementInfo, $this->renderCache, $this->rendererConfig);
