diff --git a/app/code/Magento/Braintree/Model/PaymentMethod.php b/app/code/Magento/Braintree/Model/PaymentMethod.php
index 8e14ed191e350097a62984c7570d667c149a077b..45171956e87bcf8832723f7b7dffeb90ea5f1f79 100644
--- a/app/code/Magento/Braintree/Model/PaymentMethod.php
+++ b/app/code/Magento/Braintree/Model/PaymentMethod.php
@@ -11,6 +11,7 @@ use \Braintree_Exception;
 use \Braintree_Transaction;
 use \Braintree_Result_Successful;
 use Magento\Framework\Exception\LocalizedException;
+use Magento\Sales\Model\Order\Payment\Transaction;
 use Magento\Sales\Model\ResourceModel\Order\Payment\Transaction\CollectionFactory as TransactionCollectionFactory;
 use Magento\Sales\Model\Order\Payment\Transaction as PaymentTransaction;
 use Magento\Payment\Model\InfoInterface;
@@ -648,6 +649,7 @@ class PaymentMethod extends \Magento\Payment\Model\Method\Cc
                 }
             }
 
+            // transaction should be voided if it not settled
             $canVoid = ($transaction->status === \Braintree_Transaction::AUTHORIZED
                 || $transaction->status === \Braintree_Transaction::SUBMITTED_FOR_SETTLEMENT);
             $result = $canVoid
@@ -655,6 +657,7 @@ class PaymentMethod extends \Magento\Payment\Model\Method\Cc
                 : $this->braintreeTransaction->refund($transactionId, $amount);
             $this->_debug($this->_convertObjToArray($result));
             if ($result->success) {
+                $payment->setTransactionId($transactionId . '-' . Transaction::TYPE_REFUND);
                 $payment->setIsTransactionClosed(true);
             } else {
                 throw new LocalizedException($this->errorHelper->parseBraintreeError($result));
diff --git a/app/code/Magento/Braintree/Test/Unit/Model/PaymentMethodTest.php b/app/code/Magento/Braintree/Test/Unit/Model/PaymentMethodTest.php
index f8f0494c128672811a883a0f832ae464b5f663dc..e20af765062e3b3b0713c5732d5b67f8f3c279f3 100644
--- a/app/code/Magento/Braintree/Test/Unit/Model/PaymentMethodTest.php
+++ b/app/code/Magento/Braintree/Test/Unit/Model/PaymentMethodTest.php
@@ -8,6 +8,7 @@ namespace Magento\Braintree\Test\Unit\Model;
 
 use Magento\Braintree\Model\PaymentMethod;
 use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
+use Magento\Sales\Model\Order\Payment\Transaction;
 use \Magento\Sales\Model\ResourceModel\Order\Payment\Transaction\CollectionFactory as TransactionCollectionFactory;
 use Magento\Framework\Exception\LocalizedException;
 use \Braintree_Result_Successful;
@@ -2378,6 +2379,7 @@ class PaymentMethodTest extends \PHPUnit_Framework_TestCase
 
         $this->model->refund($paymentObject, $amount);
         $this->assertEquals(1, $paymentObject->getIsTransactionClosed());
+        $this->assertEquals($refundTransactionId . '-' .Transaction::TYPE_REFUND, $paymentObject->getTransactionId());
     }
 
     /**
diff --git a/app/code/Magento/Braintree/view/adminhtml/templates/form.phtml b/app/code/Magento/Braintree/view/adminhtml/templates/form.phtml
index c27901cd4e8704fc7fdf044e47b8cc40db1a7e40..5610e082e1715e36dcecc8f7cc241bf1aeee2798 100644
--- a/app/code/Magento/Braintree/view/adminhtml/templates/form.phtml
+++ b/app/code/Magento/Braintree/view/adminhtml/templates/form.phtml
@@ -133,7 +133,7 @@ $ccExpYear = $block->getInfoData('cc_exp_year');
             </div>
         </fieldset>
     <?php endif; ?>
-    <?php if($_useVault): ?>
+    <?php if($useVault): ?>
         <fieldset class="admin__fieldset hide_if_token_selected">
             <div id="<?php /* @noEscape */ echo $code; ?>_store_in_vault_div" style="text-align:left;" class="">
                 <input type="checkbox" title="<?php echo $block->escapeHtml(__('Save this card for future use')); ?>"
diff --git a/app/code/Magento/Braintree/view/frontend/templates/creditcard/index.phtml b/app/code/Magento/Braintree/view/frontend/templates/creditcard/index.phtml
index fd9ee17028bb6eae399fe70103f3f8e82933681f..467e2523e6162efa00389deb18ecfe9f5fa43f9a 100644
--- a/app/code/Magento/Braintree/view/frontend/templates/creditcard/index.phtml
+++ b/app/code/Magento/Braintree/view/frontend/templates/creditcard/index.phtml
@@ -19,7 +19,7 @@ $storedCards = $block->getCurrentCustomerStoredCards();
     <?php endif; ?>
 </div>
 <?php echo $block->getLayout()->getMessagesBlock()->getGroupedHtml(); ?>
-<?php if (count($_storedCards)): ?>
+<?php if (count($storedCards)): ?>
     <table class="data-table" id="my-quotes-table">
         <col width="1" />
         <col width="1" />
diff --git a/app/code/Magento/Deploy/Model/Deployer.php b/app/code/Magento/Deploy/Model/Deployer.php
index cada5a4549aee90b4f18f6df5a2588dd37d82c25..60480c220e23ccc1762243ab61075bf7fb7aec7b 100644
--- a/app/code/Magento/Deploy/Model/Deployer.php
+++ b/app/code/Magento/Deploy/Model/Deployer.php
@@ -6,6 +6,7 @@
 
 namespace Magento\Deploy\Model;
 
+use Magento\Framework\View\Asset\PreProcessor\AlternativeSourceInterface;
 use Magento\Framework\App\ObjectManagerFactory;
 use Magento\Framework\App\View\Deployment\Version;
 use Magento\Framework\App\View\Asset\Publisher;
@@ -19,6 +20,7 @@ use Symfony\Component\Console\Output\OutputInterface;
  * A service for deploying Magento static view files for production mode
  *
  * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
+ * @SuppressWarnings(PHPMD.UnusedLocalVariable)
  */
 class Deployer
 {
@@ -66,10 +68,18 @@ class Deployer
     protected $jsTranslationConfig;
 
     /**
+     * @var AlternativeSourceInterface[]
+     */
+    private $alternativeSources;
+
+    /**
+     * Constructor
+     *
      * @param Files $filesUtil
      * @param OutputInterface $output
      * @param Version\StorageInterface $versionStorage
      * @param JsTranslationConfig $jsTranslationConfig
+     * @param AlternativeSourceInterface[] $alternativeSources
      * @param bool $isDryRun
      */
     public function __construct(
@@ -77,6 +87,7 @@ class Deployer
         OutputInterface $output,
         Version\StorageInterface $versionStorage,
         JsTranslationConfig $jsTranslationConfig,
+        array $alternativeSources,
         $isDryRun = false
     ) {
         $this->filesUtil = $filesUtil;
@@ -85,6 +96,13 @@ class Deployer
         $this->isDryRun = $isDryRun;
         $this->jsTranslationConfig = $jsTranslationConfig;
         $this->parentTheme = [];
+
+        array_map(
+            function (AlternativeSourceInterface $alternative) {
+            },
+            $alternativeSources
+        );
+        $this->alternativeSources = $alternativeSources;
     }
 
     /**
@@ -124,6 +142,7 @@ class Deployer
                             'design' => $design,
                         ]
                     );
+                    /** @var \Magento\RequireJs\Model\FileManager $fileManager */
                     $fileManager = $this->objectManager->create(
                         'Magento\RequireJs\Model\FileManager',
                         [
@@ -148,11 +167,17 @@ class Deployer
                                     $this->findAncestors($area . Theme::THEME_PATH_SEPARATOR . $themePath)
                                 ))
                         ) {
-                            $this->deployFile($filePath, $area, $themePath, $locale, $module);
+                            $compiledFile = $this->deployFile($filePath, $area, $themePath, $locale, $module);
+                            if ($compiledFile !== '') {
+                                $this->deployFile($compiledFile, $area, $themePath, $locale, $module);
+                            }
                         }
                     }
                     foreach ($libFiles as $filePath) {
-                        $this->deployFile($filePath, $area, $themePath, $locale, null);
+                        $compiledFile = $this->deployFile($filePath, $area, $themePath, $locale, null);
+                        if ($compiledFile !== '') {
+                            $this->deployFile($compiledFile, $area, $themePath, $locale, null);
+                        }
                     }
                     if ($this->jsTranslationConfig->dictionaryEnabled()) {
                         $this->deployFile(
@@ -169,7 +194,7 @@ class Deployer
                 }
             }
         }
-        $this->output->writeln("=== Minify templates ===");
+        $this->output->writeln('=== Minify templates ===');
         $this->count = 0;
         foreach ($this->filesUtil->getPhtmlFiles(false, false) as $template) {
             $this->htmlMinifier->minify($template);
@@ -268,15 +293,25 @@ class Deployer
      * @param string $themePath
      * @param string $locale
      * @param string $module
-     * @return void
+     * @return string
+     * @throws \InvalidArgumentException
+     *
      * @SuppressWarnings(PHPMD.NPathComplexity)
      */
     private function deployFile($filePath, $area, $themePath, $locale, $module)
     {
-        $requestedPath = $filePath;
-        if (substr($filePath, -5) == '.less') {
-            $requestedPath = preg_replace('/.less$/', '.css', $filePath);
+        $compiledFile = '';
+        $extension = pathinfo($filePath, PATHINFO_EXTENSION);
+
+        foreach ($this->alternativeSources as $name => $alternative) {
+            if (in_array($extension, $alternative->getAlternativesExtensionsNames(), true)
+                && strpos(basename($filePath), '_') !== 0
+            ) {
+                $compiledFile = substr($filePath, 0, strlen($filePath) - strlen($extension) - 1);
+                $compiledFile = $compiledFile . '.' . $name;
+            }
         }
+
         $logMessage = "Processing file '$filePath' for area '$area', theme '$themePath', locale '$locale'";
         if ($module) {
             $logMessage .= ", module '$module'";
@@ -288,7 +323,7 @@ class Deployer
 
         try {
             $asset = $this->assetRepo->createAsset(
-                $requestedPath,
+                $filePath,
                 ['area' => $area, 'theme' => $themePath, 'locale' => $locale, 'module' => $module]
             );
             if ($this->output->isVeryVerbose()) {
@@ -303,18 +338,13 @@ class Deployer
                 $this->bundleManager->addAsset($asset);
             }
             $this->count++;
-        } catch (\Less_Exception_Compiler $e) {
-            $this->verboseLog(
-                "\tNotice: Could not parse LESS file '$filePath'. "
-                . "This may indicate that the file is incomplete, but this is acceptable. "
-                . "The file '$filePath' will be combined with another LESS file."
-            );
-            $this->verboseLog("\tCompiler error: " . $e->getMessage());
         } catch (\Exception $e) {
-            $this->output->writeln($e->getMessage() . " ($logMessage)");
+            $this->output->write('.');
             $this->verboseLog($e->getTraceAsString());
             $this->errorCount++;
         }
+
+        return $compiledFile;
     }
 
     /**
diff --git a/app/code/Magento/Deploy/etc/di.xml b/app/code/Magento/Deploy/etc/di.xml
index 9d0ed7220c62a84f0dec3c4baab07c7c49e11131..59fb508c691b53a6137a129bbcc2292acf752a3d 100644
--- a/app/code/Magento/Deploy/etc/di.xml
+++ b/app/code/Magento/Deploy/etc/di.xml
@@ -6,6 +6,13 @@
  */
 -->
 <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
+    <type name="Magento\Deploy\Model\Deployer">
+        <arguments>
+            <argument name="alternativeSources" xsi:type="array">
+                <item name="css" xsi:type="object">AlternativeSourceProcessors</item>
+            </argument>
+        </arguments>
+    </type>
     <type name="Magento\Framework\Console\CommandList">
         <arguments>
             <argument name="commands" xsi:type="array">
diff --git a/app/code/Magento/Developer/Console/Command/CssDeployCommand.php b/app/code/Magento/Developer/Console/Command/CssDeployCommand.php
index 4abf04b34f01f82ef58b214bf442202634949664..ac651b633d026790bfe6d6d3a50283303e00eaa1 100644
--- a/app/code/Magento/Developer/Console/Command/CssDeployCommand.php
+++ b/app/code/Magento/Developer/Console/Command/CssDeployCommand.php
@@ -6,6 +6,7 @@
 
 namespace Magento\Developer\Console\Command;
 
+use Magento\Framework\View\Asset\PreProcessor\Pool;
 use Symfony\Component\Console\Command\Command;
 use Symfony\Component\Console\Input\InputArgument;
 use Symfony\Component\Console\Input\InputOption;
@@ -17,7 +18,6 @@ use Magento\Framework\App\State;
 use Magento\Framework\View\Asset\Repository;
 use Magento\Framework\ObjectManagerInterface;
 use Magento\Framework\App\ObjectManager\ConfigLoader;
-use Magento\Framework\View\Asset\SourceFileGeneratorPool;
 use Magento\Framework\View\Asset\PreProcessor\ChainFactoryInterface;
 use Magento\Framework\App\Filesystem\DirectoryList;
 use Magento\Framework\Validator\Locale;
@@ -73,11 +73,6 @@ class CssDeployCommand extends Command
      */
     private $state;
 
-    /**
-     * @var SourceFileGeneratorPool
-     */
-    private $sourceFileGeneratorPool;
-
     /**
      * @var Source
      */
@@ -98,6 +93,11 @@ class CssDeployCommand extends Command
      */
     private $validator;
 
+    /**
+     * @var Pool
+     */
+    private $pool;
+
     /**
      * Inject dependencies
      *
@@ -106,10 +106,10 @@ class CssDeployCommand extends Command
      * @param ConfigLoader $configLoader
      * @param State $state
      * @param Source $assetSource
-     * @param SourceFileGeneratorPool $sourceFileGeneratorPoll
      * @param ChainFactoryInterface $chainFactory
      * @param Filesystem $filesystem
      * @param Locale $validator
+     * @param Pool $pool
      */
     public function __construct(
         ObjectManagerInterface $objectManager,
@@ -117,22 +117,22 @@ class CssDeployCommand extends Command
         ConfigLoader $configLoader,
         State $state,
         Source $assetSource,
-        SourceFileGeneratorPool $sourceFileGeneratorPoll,
         ChainFactoryInterface $chainFactory,
         Filesystem $filesystem,
-        Locale $validator
+        Locale $validator,
+        Pool $pool
     ) {
         $this->state = $state;
         $this->objectManager = $objectManager;
         $this->configLoader = $configLoader;
         $this->assetRepo = $assetRepo;
-        $this->sourceFileGeneratorPool = $sourceFileGeneratorPoll;
         $this->assetSource = $assetSource;
         $this->chainFactory = $chainFactory;
         $this->filesystem = $filesystem;
         $this->validator = $validator;
 
         parent::__construct();
+        $this->pool = $pool;
     }
 
     /**
@@ -203,8 +203,6 @@ class CssDeployCommand extends Command
         $this->state->setAreaCode($area);
         $this->objectManager->configure($this->configLoader->load($area));
 
-        $sourceFileGenerator = $this->sourceFileGeneratorPool->create($type);
-
         foreach ($input->getArgument(self::FILE_ARGUMENT) as $file) {
             $file .= '.' . $type;
 
@@ -233,14 +231,11 @@ class CssDeployCommand extends Command
                 ]
             );
 
-            $processedCoreFile = $sourceFileGenerator->generateFileTree($chain);
-
+            $this->pool->process($chain);
             $targetDir = $this->filesystem->getDirectoryWrite(DirectoryList::STATIC_VIEW);
-            $source = $rootDir->getRelativePath($processedCoreFile);
-            $destination = $asset->getPath();
-            $rootDir->copyFile($source, $destination, $targetDir);
+            $targetDir->writeFile($chain->getAsset()->getPath(), $chain->getContent());
 
-            $output->writeln("<info>Successfully processed dynamic stylesheet into CSS</info>");
+            $output->writeln('<info>Successfully processed dynamic stylesheet into CSS</info>');
         }
     }
 }
diff --git a/app/code/Magento/Developer/Test/Unit/Console/Command/CssDeployCommandTest.php b/app/code/Magento/Developer/Test/Unit/Console/Command/CssDeployCommandTest.php
index d274aa003133d2bd6a8bebc061113cb6e94cfd5d..0d930989e424eefbcd192c0c3ca33322c13ba06a 100644
--- a/app/code/Magento/Developer/Test/Unit/Console/Command/CssDeployCommandTest.php
+++ b/app/code/Magento/Developer/Test/Unit/Console/Command/CssDeployCommandTest.php
@@ -7,17 +7,20 @@
 namespace Magento\Developer\Test\Unit\Console\Command;
 
 use Magento\Framework\Filesystem;
+use Magento\Framework\View\Asset\PreProcessor\Pool;
 use Magento\Framework\View\Asset\Source;
 use Magento\Framework\App\State;
 use Magento\Framework\View\Asset\Repository;
 use Magento\Framework\ObjectManagerInterface;
 use Magento\Framework\App\ObjectManager\ConfigLoader;
-use Magento\Framework\View\Asset\SourceFileGeneratorPool;
 use Magento\Framework\View\Asset\PreProcessor\ChainFactoryInterface;
 use Magento\Developer\Console\Command\CssDeployCommand;
 use Symfony\Component\Console\Tester\CommandTester;
 use Magento\Framework\Validator\Locale;
 
+/**
+ * Class CssDeployCommandTest
+ */
 class CssDeployCommandTest extends \PHPUnit_Framework_TestCase
 {
     /**
@@ -45,11 +48,6 @@ class CssDeployCommandTest extends \PHPUnit_Framework_TestCase
      */
     private $state;
 
-    /**
-     * @var SourceFileGeneratorPool|\PHPUnit_Framework_MockObject_MockObject
-     */
-    private $sourceFileGeneratorPool;
-
     /**
      * @var Source|\PHPUnit_Framework_MockObject_MockObject
      */
@@ -70,6 +68,11 @@ class CssDeployCommandTest extends \PHPUnit_Framework_TestCase
      */
     private $validator;
 
+    /**
+     * @var Pool|\PHPUnit_Framework_MockObject_MockObject
+     */
+    private $poolMock;
+
     public function setUp()
     {
         $this->objectManager = $this->getMockForAbstractClass('Magento\Framework\ObjectManagerInterface');
@@ -77,18 +80,14 @@ class CssDeployCommandTest extends \PHPUnit_Framework_TestCase
         $this->configLoader = $this->getMock('Magento\Framework\App\ObjectManager\ConfigLoader', [], [], '', false);
         $this->state = $this->getMock('Magento\Framework\App\State', [], [], '', false);
         $this->assetSource = $this->getMock('Magento\Framework\View\Asset\Source', [], [], '', false);
-        $this->sourceFileGeneratorPool = $this->getMock(
-            'Magento\Framework\View\Asset\SourceFileGeneratorPool',
-            [],
-            [],
-            '',
-            false
-        );
         $this->chainFactory = $this->getMockForAbstractClass(
             'Magento\Framework\View\Asset\PreProcessor\ChainFactoryInterface'
         );
         $this->filesystem = $this->getMock('Magento\Framework\Filesystem', [], [], '', false);
         $this->validator = $this->getMock('Magento\Framework\Validator\Locale', [], [], '', false);
+        $this->poolMock = $this->getMockBuilder('Magento\Framework\View\Asset\PreProcessor\Pool')
+            ->disableOriginalConstructor()
+            ->getMock();
 
         $this->command = new CssDeployCommand(
             $this->objectManager,
@@ -96,10 +95,10 @@ class CssDeployCommandTest extends \PHPUnit_Framework_TestCase
             $this->configLoader,
             $this->state,
             $this->assetSource,
-            $this->sourceFileGeneratorPool,
             $this->chainFactory,
             $this->filesystem,
-            $this->validator
+            $this->validator,
+            $this->poolMock
         );
     }
 
@@ -109,10 +108,6 @@ class CssDeployCommandTest extends \PHPUnit_Framework_TestCase
 
         $this->configLoader->expects($this->once())->method('load')->with('frontend')->willReturn([]);
         $this->objectManager->expects($this->once())->method('configure');
-        $this->sourceFileGeneratorPool->expects($this->once())
-            ->method('create')
-            ->with('less')
-            ->willReturn($this->getMock('Magento\Framework\View\Asset\SourceFileGeneratorInterface'));
         $asset = $this->getMockForAbstractClass('Magento\Framework\View\Asset\LocalInterface');
         $asset->expects($this->once())->method('getContentType')->willReturn('type');
         $this->assetRepo->expects($this->once())
@@ -128,6 +123,10 @@ class CssDeployCommandTest extends \PHPUnit_Framework_TestCase
             ->willReturn($asset);
         $this->assetSource->expects($this->once())->method('findSource')->willReturn('/dev/null');
 
+        $chainMock = $this->getMock('Magento\Framework\View\Asset\PreProcessor\Chain', [], [], '', false);
+        $assetMock = $this->getMockBuilder('Magento\Framework\View\Asset\LocalInterface')
+            ->getMockForAbstractClass();
+
         $this->chainFactory->expects($this->once())
             ->method('create')
             ->with(
@@ -137,8 +136,11 @@ class CssDeployCommandTest extends \PHPUnit_Framework_TestCase
                     'origContentType' => 'type',
                     'origAssetPath' => 'relative/path',
                 ]
-            )
-            ->willReturn($this->getMock('Magento\Framework\View\Asset\PreProcessor\Chain', [], [], '', false));
+            )->willReturn($chainMock);
+
+        $chainMock->expects(self::once())
+            ->method('getAsset')
+            ->willReturn($assetMock);
 
         $rootDir = $this->getMock('\Magento\Framework\Filesystem\Directory\WriteInterface', [], [], '', false);
         $this->filesystem->expects($this->at(0))->method('getDirectoryWrite')->willReturn($rootDir);
diff --git a/app/code/Magento/Developer/etc/di.xml b/app/code/Magento/Developer/etc/di.xml
index c43c9e06ca2cfe9e1eee412b80729f12d1079df7..a208ec7c5de01f26250b2a93d5d571732899c2d6 100644
--- a/app/code/Magento/Developer/etc/di.xml
+++ b/app/code/Magento/Developer/etc/di.xml
@@ -8,7 +8,7 @@
 <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
     <preference for="Magento\Framework\View\Asset\PreProcessor\ChainFactoryInterface" type="Magento\Developer\Model\View\Asset\PreProcessor\DeveloperChainFactory"/>
     <preference for="Magento\Framework\Css\PreProcessor\ErrorHandlerInterface" type="Magento\Framework\Css\PreProcessor\ErrorHandler" />
-    <preference for="Magento\Framework\Css\PreProcessor\AdapterInterface" type="Magento\Framework\Css\PreProcessor\Adapter\Less\Oyejorge" />
+    <preference for="Magento\Framework\View\Asset\PreProcessor\Helper\SortInterface" type="Magento\Framework\View\Asset\PreProcessor\Helper\Sort"/>
 
     <type name="Magento\Framework\View\Result\Page">
         <arguments>
@@ -45,52 +45,58 @@
         </arguments>
     </virtualType>
 
+    <virtualType name="viewFileFallbackResolver" type="Magento\Framework\View\Design\FileResolution\Fallback\Resolver\Alternative"/>
 
-
-    <virtualType name="viewFileFallbackResolver" type="Magento\Framework\View\Design\FileResolution\Fallback\Resolver\Alternative">
+    <virtualType name="AlternativeSourceProcessors" type="Magento\Framework\View\Asset\PreProcessor\AlternativeSource">
         <arguments>
-            <argument name="alternativeExtensions" xsi:type="array">
-                <item name="css" xsi:type="array">
-                    <item name="less" xsi:type="string">less</item>
+            <argument name="lockName" xsi:type="string">alternative-source-css</argument>
+            <argument name="lockerProcess" xsi:type="object">Magento\Framework\View\Asset\LockerProcess</argument>
+            <argument name="alternatives" xsi:type="array">
+                <item name="less" xsi:type="array">
+                    <item name="class" xsi:type="string">Magento\Framework\Css\PreProcessor\Adapter\Less\Processor</item>
                 </item>
             </argument>
         </arguments>
     </virtualType>
+
     <type name="Magento\Framework\View\Asset\PreProcessor\Pool">
         <arguments>
-            <argument name="preProcessors" xsi:type="array">
+            <argument name="defaultPreprocessor" xsi:type="string">Magento\Framework\View\Asset\PreProcessor\Passthrough</argument>
+            <argument name="preprocessors" xsi:type="array">
                 <item name="less" xsi:type="array">
-                    <item name="css" xsi:type="array">
-                        <item name="less" xsi:type="string">Magento\Framework\Css\PreProcessor\Less</item>
-                        <item name="variable_notation" xsi:type="string">Magento\Framework\View\Asset\PreProcessor\VariableNotation</item>
-                        <item name="module_notation" xsi:type="string">Magento\Framework\View\Asset\PreProcessor\ModuleNotation</item>
-                        <item name="css_min" xsi:type="string">cssMinificationProcessor</item>
+                    <item name="magento_import" xsi:type="array">
+                        <item name="class" xsi:type="string">Magento\Framework\Css\PreProcessor\Instruction\MagentoImport</item>
                     </item>
-                    <item name="less" xsi:type="array">
-                        <item name="magento_import" xsi:type="string">Magento\Framework\Css\PreProcessor\Instruction\MagentoImport</item>
-                        <item name="import" xsi:type="string">Magento\Framework\Css\PreProcessor\Instruction\Import</item>
+                    <item name="import" xsi:type="array">
+                        <item name="after" xsi:type="string">magento_import</item>
+                        <item name="class" xsi:type="string">Magento\Framework\Css\PreProcessor\Instruction\Import</item>
                     </item>
                 </item>
                 <item name="css" xsi:type="array">
-                    <item name="css" xsi:type="array">
-                        <item name="variable_notation" xsi:type="string">Magento\Framework\View\Asset\PreProcessor\VariableNotation</item>
-                        <item name="module_notation" xsi:type="string">Magento\Framework\View\Asset\PreProcessor\ModuleNotation</item>
-                        <item name="css_min" xsi:type="string">cssMinificationProcessor</item>
+                    <item name="alternativeSource" xsi:type="array">
+                        <item name="class" xsi:type="string">AlternativeSourceProcessors</item>
+                    </item>
+                    <item name="variable_notation" xsi:type="array">
+                        <item name="after" xsi:type="string">alternativeSource</item>
+                        <item name="class" xsi:type="string">Magento\Framework\View\Asset\PreProcessor\VariableNotation</item>
+                    </item>
+                    <item name="module_notation" xsi:type="array">
+                        <item name="after" xsi:type="string">variable_notation</item>
+                        <item name="class" xsi:type="string">Magento\Framework\View\Asset\PreProcessor\ModuleNotation</item>
+                    </item>
+                    <item name="css_min" xsi:type="array">
+                        <item name="after" xsi:type="string">module_notation</item>
+                        <item name="class" xsi:type="string">cssMinificationProcessor</item>
                     </item>
                 </item>
                 <item name="js" xsi:type="array">
-                    <item name="js" xsi:type="array">
-                        <item name="js_min" xsi:type="string">jsMinificationProcessor</item>
+                    <item name="js_min" xsi:type="array">
+                        <item name="class" xsi:type="string">jsMinificationProcessor</item>
                     </item>
                 </item>
             </argument>
         </arguments>
     </type>
-    <type name="Magento\Framework\Css\PreProcessor\Less">
-        <arguments>
-            <argument name="adapter" xsi:type="object">Magento\Framework\Css\PreProcessor\Adapter\Less\Oyejorge</argument>
-        </arguments>
-    </type>
 
     <type name="Magento\Framework\Css\PreProcessor\Instruction\MagentoImport">
         <arguments>
@@ -126,22 +132,4 @@
             <argument name="subDir" xsi:type="string">web</argument>
         </arguments>
     </virtualType>
-
-    <type name="Magento\Framework\View\Asset\SourceFileGeneratorPool">
-        <arguments>
-            <argument name="fileGeneratorTypes" xsi:type="array">
-                <item name="less" xsi:type="object">fileAssemblerFileGenerator</item>
-            </argument>
-        </arguments>
-    </type>
-    <virtualType name="fileAssemblerFileGenerator" type="Magento\Framework\Css\PreProcessor\FileGenerator">
-        <arguments>
-            <argument name="relatedGenerator" xsi:type="object">fileAssemblerRelatedFilesGenerator</argument>
-        </arguments>
-    </virtualType>
-    <virtualType name="fileAssemblerRelatedFilesGenerator" type="Magento\Developer\Model\Css\PreProcessor\FileGenerator\PublicationDecorator">
-        <arguments>
-            <argument name="publisher" xsi:type="object">developerPublisher</argument>
-        </arguments>
-    </virtualType>
 </config>
diff --git a/app/code/Magento/Email/Model/Template/Filter.php b/app/code/Magento/Email/Model/Template/Filter.php
index ebe3d0d8e2974409158217668265124e261bc860..a3cb0a5999688c6ad09a2175663835b3333eea50 100644
--- a/app/code/Magento/Email/Model/Template/Filter.php
+++ b/app/code/Magento/Email/Model/Template/Filter.php
@@ -5,6 +5,8 @@
  */
 namespace Magento\Email\Model\Template;
 
+use Magento\Framework\View\Asset\ContentProcessorInterface;
+
 /**
  * Core Email Template Filter Model
  *
@@ -64,7 +66,7 @@ class Filter extends \Magento\Framework\Filter\Template
      *
      * @var int
      */
-    protected $_storeId = null;
+    protected $_storeId;
 
     /**
      * @var array
@@ -89,7 +91,7 @@ class Filter extends \Magento\Framework\Filter\Template
     /**
      * @var \Magento\Framework\Escaper
      */
-    protected $_escaper = null;
+    protected $_escaper;
 
     /**
      * Core store config
@@ -787,7 +789,7 @@ class Filter extends \Magento\Framework\Filter\Template
 
         $css = $this->getCssFilesContent([$params['file']]);
 
-        if (strpos($css, \Magento\Framework\Css\PreProcessor\AdapterInterface::ERROR_MESSAGE_PREFIX) !== false) {
+        if (strpos($css, ContentProcessorInterface::ERROR_MESSAGE_PREFIX) !== false) {
             // Return compilation error wrapped in CSS comment
             return '/*' . PHP_EOL . $css . PHP_EOL . '*/';
         } elseif (!empty($css)) {
@@ -908,7 +910,7 @@ class Filter extends \Magento\Framework\Filter\Template
         if ($html && $cssToInline) {
             try {
                 // Don't try to compile CSS that has compilation errors
-                if (strpos($cssToInline, \Magento\Framework\Css\PreProcessor\AdapterInterface::ERROR_MESSAGE_PREFIX)
+                if (strpos($cssToInline, ContentProcessorInterface::ERROR_MESSAGE_PREFIX)
                     !== false
                 ) {
                     throw new \Magento\Framework\Exception\MailException(
diff --git a/app/code/Magento/Email/Test/Unit/Model/Template/FilterTest.php b/app/code/Magento/Email/Test/Unit/Model/Template/FilterTest.php
index a21a6dbd30bf1b2c72d2c81b412d2c3bd9d321ab..cd7b55f4499e7a59564dfb73c94bfe0538b61d5f 100644
--- a/app/code/Magento/Email/Test/Unit/Model/Template/FilterTest.php
+++ b/app/code/Magento/Email/Test/Unit/Model/Template/FilterTest.php
@@ -282,7 +282,7 @@ class FilterTest extends \PHPUnit_Framework_TestCase
             ],
             'CSS with error does not get inlined' => [
                 '<html><p></p></html>',
-                \Magento\Framework\Css\PreProcessor\AdapterInterface::ERROR_MESSAGE_PREFIX,
+                \Magento\Framework\View\Asset\ContentProcessorInterface::ERROR_MESSAGE_PREFIX,
                 ['<html><p></p></html>'],
             ],
             'Ensure disableStyleBlocksParsing option is working' => [
diff --git a/app/code/Magento/Payment/Gateway/Command/CommandPool.php b/app/code/Magento/Payment/Gateway/Command/CommandPool.php
index 6b1014d5aa76d9fefb8a1efb80583147067f2853..d1fc52a72378248b3a9cc87da3fd36d133924d93 100644
--- a/app/code/Magento/Payment/Gateway/Command/CommandPool.php
+++ b/app/code/Magento/Payment/Gateway/Command/CommandPool.php
@@ -18,17 +18,17 @@ class CommandPool implements CommandPoolInterface
     private $commands;
 
     /**
-     * @param array $commands
      * @param TMapFactory $tmapFactory
+     * @param array $commands
      */
     public function __construct(
-        array $commands,
-        TMapFactory $tmapFactory
+        TMapFactory $tmapFactory,
+        array $commands = []
     ) {
         $this->commands = $tmapFactory->create(
             [
                 'array' => $commands,
-                'type' => 'Magento\Payment\Gateway\CommandInterface'
+                'type' => CommandInterface::class
             ]
         );
     }
diff --git a/app/code/Magento/Payment/Gateway/Config/ValueHandlerPool.php b/app/code/Magento/Payment/Gateway/Config/ValueHandlerPool.php
index 0364336a2ea5e42df84c190359218276bd2aa168..b23964b064274e9e4d475c46a23d3448ff32024a 100644
--- a/app/code/Magento/Payment/Gateway/Config/ValueHandlerPool.php
+++ b/app/code/Magento/Payment/Gateway/Config/ValueHandlerPool.php
@@ -21,12 +21,12 @@ class ValueHandlerPool implements \Magento\Payment\Gateway\Config\ValueHandlerPo
     private $handlers;
 
     /**
-     * @param array $handlers
      * @param TMapFactory $tmapFactory
+     * @param array $handlers
      */
     public function __construct(
-        array $handlers,
-        TMapFactory $tmapFactory
+        TMapFactory $tmapFactory,
+        array $handlers
     ) {
         if (!isset($handlers[self::DEFAULT_HANDLER])) {
             throw new \LogicException('Default handler should be provided.');
@@ -35,7 +35,7 @@ class ValueHandlerPool implements \Magento\Payment\Gateway\Config\ValueHandlerPo
         $this->handlers = $tmapFactory->create(
             [
                 'array' => $handlers,
-                'type' => 'Magento\Payment\Gateway\Config\ValueHandlerInterface'
+                'type' => ValueHandlerInterface::class
             ]
         );
     }
diff --git a/app/code/Magento/Payment/Gateway/Request/BuilderComposite.php b/app/code/Magento/Payment/Gateway/Request/BuilderComposite.php
index 66584773b638dfdc05a233ff4db10a7b1272794f..43f39b2932b40b81f06b0788f7b22827fda9f2fc 100644
--- a/app/code/Magento/Payment/Gateway/Request/BuilderComposite.php
+++ b/app/code/Magento/Payment/Gateway/Request/BuilderComposite.php
@@ -19,17 +19,17 @@ class BuilderComposite implements BuilderInterface
     private $builders;
 
     /**
-     * @param array $builders
      * @param TMapFactory $tmapFactory
+     * @param array $builders
      */
     public function __construct(
-        array $builders,
-        TMapFactory $tmapFactory
+        TMapFactory $tmapFactory,
+        array $builders = []
     ) {
         $this->builders = $tmapFactory->create(
             [
                 'array' => $builders,
-                'type' => 'Magento\Payment\Gateway\Request\BuilderInterface'
+                'type' => BuilderInterface::class
             ]
         );
     }
diff --git a/app/code/Magento/Payment/Gateway/Response/HandlerChain.php b/app/code/Magento/Payment/Gateway/Response/HandlerChain.php
index 1425514e7e3fb87054fdb09690d49d53c0b52a72..6a45311d5eb897b0ec15794cccc838995b747c04 100644
--- a/app/code/Magento/Payment/Gateway/Response/HandlerChain.php
+++ b/app/code/Magento/Payment/Gateway/Response/HandlerChain.php
@@ -16,17 +16,17 @@ class HandlerChain implements HandlerInterface
     private $handlers;
 
     /**
-     * @param array $handlers
      * @param TMapFactory $tmapFactory
+     * @param array $handlers
      */
     public function __construct(
-        array $handlers,
-        TMapFactory $tmapFactory
+        TMapFactory $tmapFactory,
+        array $handlers = []
     ) {
         $this->handlers = $tmapFactory->create(
             [
                 'array' => $handlers,
-                'type' => 'Magento\Payment\Gateway\Response\HandlerInterface'
+                'type' => HandlerInterface::class
             ]
         );
     }
diff --git a/app/code/Magento/Payment/Gateway/Validator/ValidatorComposite.php b/app/code/Magento/Payment/Gateway/Validator/ValidatorComposite.php
index 6e7c5c8c0ab5cecf0031ebc87519306289ea40e2..b36ceed14bdfa991d9fad107e120bb4b312a5316 100644
--- a/app/code/Magento/Payment/Gateway/Validator/ValidatorComposite.php
+++ b/app/code/Magento/Payment/Gateway/Validator/ValidatorComposite.php
@@ -18,18 +18,18 @@ class ValidatorComposite extends AbstractValidator
 
     /**
      * @param ResultInterfaceFactory $resultFactory
-     * @param array $validators
      * @param TMapFactory $tmapFactory
+     * @param array $validators
      */
     public function __construct(
         ResultInterfaceFactory $resultFactory,
-        array $validators,
-        TMapFactory $tmapFactory
+        TMapFactory $tmapFactory,
+        array $validators = []
     ) {
         $this->validators = $tmapFactory->create(
             [
                 'array' => $validators,
-                'type' => 'Magento\Payment\Gateway\Validator\ValidatorInterface'
+                'type' => ValidatorInterface::class
             ]
         );
         parent::__construct($resultFactory);
diff --git a/app/code/Magento/Payment/Gateway/Validator/ValidatorPool.php b/app/code/Magento/Payment/Gateway/Validator/ValidatorPool.php
index e2b746ea7334f480ef5fa3a83358081cea3289db..6697dd86c3d883ae85293b0307435820fb069e0e 100644
--- a/app/code/Magento/Payment/Gateway/Validator/ValidatorPool.php
+++ b/app/code/Magento/Payment/Gateway/Validator/ValidatorPool.php
@@ -17,17 +17,17 @@ class ValidatorPool implements \Magento\Payment\Gateway\Validator\ValidatorPoolI
     private $validators;
 
     /**
-     * @param array $validators
      * @param TMapFactory $tmapFactory
+     * @param array $validators
      */
     public function __construct(
-        array $validators,
-        TMapFactory $tmapFactory
+        TMapFactory $tmapFactory,
+        array $validators = []
     ) {
         $this->validators = $tmapFactory->create(
             [
                 'array' => $validators,
-                'type' => 'Magento\Payment\Gateway\Validator\ValidatorInterface'
+                'type' => ValidatorInterface::class
             ]
         );
     }
diff --git a/app/code/Magento/Payment/Model/Method/Logger.php b/app/code/Magento/Payment/Model/Method/Logger.php
index 7e7331b77df73d9f87624d733167eed0b9cdff08..47c91a25968ccb5560280e78659eebd892787308 100644
--- a/app/code/Magento/Payment/Model/Method/Logger.php
+++ b/app/code/Magento/Payment/Model/Method/Logger.php
@@ -41,21 +41,21 @@ class Logger
     /**
      * Logs payment related information used for debug
      *
-     * @param array $debugData
-     * @param array|null $debugReplaceKeys
-     * @param bool|null $debugFlag
+     * @param array $data
+     * @param array|null $maskKeys
+     * @param bool|null $forceDebug
      * @return void
      */
-    public function debug(array $debugData, array $debugReplaceKeys = null, $debugFlag = null)
+    public function debug(array $data, array $maskKeys = null, $forceDebug = null)
     {
-        $debugReplaceKeys = $debugReplaceKeys !== null ? $debugReplaceKeys : $this->getDebugReplaceFields();
-        $debugFlag = $debugFlag !== null ? $debugFlag : $this->isDebugOn();
-        if ($debugFlag === true && !empty($debugData) && !empty($debugReplaceKeys)) {
-            $debugData = $this->filterDebugData(
-                $debugData,
-                $debugReplaceKeys
+        $maskKeys = $maskKeys !== null ? $maskKeys : $this->getDebugReplaceFields();
+        $debugOn = $forceDebug !== null ? $forceDebug : $this->isDebugOn();
+        if ($debugOn === true) {
+            $data = $this->filterDebugData(
+                $data,
+                $maskKeys
             );
-            $this->logger->debug(var_export($debugData, true));
+            $this->logger->debug(var_export($data, true));
         }
     }
 
@@ -66,7 +66,7 @@ class Logger
      */
     private function getDebugReplaceFields()
     {
-        if ($this->config->getValue('debugReplaceKeys')) {
+        if ($this->config and $this->config->getValue('debugReplaceKeys')) {
             return explode(',', $this->config->getValue('debugReplaceKeys'));
         }
         return [];
@@ -79,7 +79,7 @@ class Logger
      */
     private function isDebugOn()
     {
-        return (bool)$this->config->getValue('debug');
+        return $this->config and (bool)$this->config->getValue('debug');
     }
 
     /**
diff --git a/app/code/Magento/Payment/Test/Unit/Gateway/Command/CommandPoolTest.php b/app/code/Magento/Payment/Test/Unit/Gateway/Command/CommandPoolTest.php
index 92394d8bb330ed66ed9fb6dc98f49666fb725155..7ab96f4474e497d197f4c91298e2e44430e5ccef 100644
--- a/app/code/Magento/Payment/Test/Unit/Gateway/Command/CommandPoolTest.php
+++ b/app/code/Magento/Payment/Test/Unit/Gateway/Command/CommandPoolTest.php
@@ -6,6 +6,7 @@
 namespace Magento\Payment\Test\Unit\Gateway\Command;
 
 use Magento\Payment\Gateway\Command\CommandPool;
+use Magento\Payment\Gateway\CommandInterface;
 
 class CommandPoolTest extends \PHPUnit_Framework_TestCase
 {
@@ -26,7 +27,7 @@ class CommandPoolTest extends \PHPUnit_Framework_TestCase
             ->with(
                 [
                     'array' => ['Magento\Payment\Gateway\CommandInterface'],
-                    'type' => 'Magento\Payment\Gateway\CommandInterface'
+                    'type' => CommandInterface::class
                 ]
             )
             ->willReturn($tMap);
@@ -39,7 +40,7 @@ class CommandPoolTest extends \PHPUnit_Framework_TestCase
             ->with('command')
             ->willReturn($commandI);
 
-        $pool = new CommandPool(['Magento\Payment\Gateway\CommandInterface'], $tMapFactory);
+        $pool = new CommandPool($tMapFactory, ['Magento\Payment\Gateway\CommandInterface']);
 
         static::assertSame($commandI, $pool->get('command'));
     }
@@ -61,7 +62,7 @@ class CommandPoolTest extends \PHPUnit_Framework_TestCase
             ->with(
                 [
                     'array' => [],
-                    'type' => 'Magento\Payment\Gateway\CommandInterface'
+                    'type' => CommandInterface::class
                 ]
             )
             ->willReturn($tMap);
@@ -70,7 +71,7 @@ class CommandPoolTest extends \PHPUnit_Framework_TestCase
             ->with('command')
             ->willReturn(false);
 
-        $pool = new CommandPool([], $tMapFactory);
+        $pool = new CommandPool($tMapFactory, []);
         $pool->get('command');
     }
 }
diff --git a/app/code/Magento/Payment/Test/Unit/Gateway/Config/ValueHandlerPoolTest.php b/app/code/Magento/Payment/Test/Unit/Gateway/Config/ValueHandlerPoolTest.php
index 266128b42f6f9ee21b26c83e5e3caf0187163998..cac2d6c1c9d21b030c57b9cde07b8452b7b47e4b 100644
--- a/app/code/Magento/Payment/Test/Unit/Gateway/Config/ValueHandlerPoolTest.php
+++ b/app/code/Magento/Payment/Test/Unit/Gateway/Config/ValueHandlerPoolTest.php
@@ -5,6 +5,7 @@
  */
 namespace Magento\Payment\Test\Unit\Gateway\Config;
 
+use Magento\Payment\Gateway\Config\ValueHandlerInterface;
 use Magento\Payment\Gateway\Config\ValueHandlerPool;
 
 class ValueHandlerPoolTest extends \PHPUnit_Framework_TestCase
@@ -19,7 +20,7 @@ class ValueHandlerPoolTest extends \PHPUnit_Framework_TestCase
 
         $tMapFactory->expects(static::never())
             ->method('create');
-        new ValueHandlerPool([], $tMapFactory);
+        new ValueHandlerPool($tMapFactory, []);
     }
 
     public function testGet()
@@ -46,7 +47,7 @@ class ValueHandlerPoolTest extends \PHPUnit_Framework_TestCase
                         ValueHandlerPool::DEFAULT_HANDLER => 'Magento\Payment\Gateway\Config\ValueHandlerInterface',
                         'some_value' => 'Magento\Payment\Gateway\Config\ValueHandlerInterface'
                     ],
-                    'type' => 'Magento\Payment\Gateway\Config\ValueHandlerInterface'
+                    'type' => ValueHandlerInterface::class
                 ]
             )
             ->willReturn($tMap);
@@ -68,11 +69,11 @@ class ValueHandlerPoolTest extends \PHPUnit_Framework_TestCase
             );
 
         $pool = new ValueHandlerPool(
+            $tMapFactory,
             [
                 ValueHandlerPool::DEFAULT_HANDLER => 'Magento\Payment\Gateway\Config\ValueHandlerInterface',
                 'some_value' => 'Magento\Payment\Gateway\Config\ValueHandlerInterface'
-            ],
-            $tMapFactory
+            ]
         );
         static::assertSame($someValueHandler, $pool->get('some_value'));
         static::assertSame($defaultHandler, $pool->get(ValueHandlerPool::DEFAULT_HANDLER));
diff --git a/app/code/Magento/Payment/Test/Unit/Gateway/Request/BuilderCompositeTest.php b/app/code/Magento/Payment/Test/Unit/Gateway/Request/BuilderCompositeTest.php
index e1e5ea547456a76f23629322b483718b5cf98e61..2c31c318db6780e30a087305e770fad38e181436 100644
--- a/app/code/Magento/Payment/Test/Unit/Gateway/Request/BuilderCompositeTest.php
+++ b/app/code/Magento/Payment/Test/Unit/Gateway/Request/BuilderCompositeTest.php
@@ -6,6 +6,7 @@
 namespace Magento\Payment\Test\Unit\Gateway\Request;
 
 use Magento\Payment\Gateway\Request\BuilderComposite;
+use Magento\Payment\Gateway\Request\BuilderInterface;
 
 class BuilderCompositeTest extends \PHPUnit_Framework_TestCase
 {
@@ -24,7 +25,7 @@ class BuilderCompositeTest extends \PHPUnit_Framework_TestCase
             ->with(
                 [
                     'array' => [],
-                    'type' => 'Magento\Payment\Gateway\Request\BuilderInterface'
+                    'type' => BuilderInterface::class
                 ]
             )
             ->willReturn($tMap);
@@ -32,7 +33,7 @@ class BuilderCompositeTest extends \PHPUnit_Framework_TestCase
             ->method('getIterator')
             ->willReturn(new \ArrayIterator([]));
 
-        $builder = new BuilderComposite([], $tMapFactory);
+        $builder = new BuilderComposite($tMapFactory, []);
         static::assertEquals([], $builder->build([]));
     }
 
@@ -47,6 +48,7 @@ class BuilderCompositeTest extends \PHPUnit_Framework_TestCase
             'item' => 'gas cooker',
             'quantity' => 1
         ];
+
         $tMapFactory = $this->getMockBuilder('Magento\Framework\ObjectManager\TMapFactory')
             ->disableOriginalConstructor()
             ->setMethods(['create'])
@@ -96,7 +98,7 @@ class BuilderCompositeTest extends \PHPUnit_Framework_TestCase
                         'product' => 'Magento\Payment\Gateway\Request\BuilderInterface',
                         'magento' => 'Magento\Payment\Gateway\Request\BuilderInterface'
                     ],
-                    'type' => 'Magento\Payment\Gateway\Request\BuilderInterface'
+                    'type' => BuilderInterface::class
                 ]
             )
             ->willReturn($tMap);
@@ -105,12 +107,12 @@ class BuilderCompositeTest extends \PHPUnit_Framework_TestCase
             ->willReturn(new \ArrayIterator([$customerBuilder, $productBuilder, $magentoBuilder]));
 
         $builder = new BuilderComposite(
+            $tMapFactory,
             [
                 'customer' => 'Magento\Payment\Gateway\Request\BuilderInterface',
                 'product' => 'Magento\Payment\Gateway\Request\BuilderInterface',
                 'magento' => 'Magento\Payment\Gateway\Request\BuilderInterface'
-            ],
-            $tMapFactory
+            ]
         );
 
         static::assertEquals($expectedRequest, $builder->build([]));
diff --git a/app/code/Magento/Payment/Test/Unit/Gateway/Response/HandlerChainTest.php b/app/code/Magento/Payment/Test/Unit/Gateway/Response/HandlerChainTest.php
index c65a826a2624d79adff61fac919ce47385fac6ac..78891068b4cc07fd7a10aa9d80d333f65012cc83 100644
--- a/app/code/Magento/Payment/Test/Unit/Gateway/Response/HandlerChainTest.php
+++ b/app/code/Magento/Payment/Test/Unit/Gateway/Response/HandlerChainTest.php
@@ -6,6 +6,7 @@
 namespace Magento\Payment\Test\Unit\Gateway\Response;
 
 use Magento\Payment\Gateway\Response\HandlerChain;
+use Magento\Payment\Gateway\Response\HandlerInterface;
 
 class HandlerChainTest extends \PHPUnit_Framework_TestCase
 {
@@ -31,7 +32,7 @@ class HandlerChainTest extends \PHPUnit_Framework_TestCase
                         'handler1' => 'Magento\Payment\Gateway\Response\HandlerInterface',
                         'handler2' => 'Magento\Payment\Gateway\Response\HandlerInterface'
                     ],
-                    'type' => 'Magento\Payment\Gateway\Response\HandlerInterface'
+                    'type' => HandlerInterface::class
                 ]
             )
             ->willReturn($tMap);
@@ -49,11 +50,11 @@ class HandlerChainTest extends \PHPUnit_Framework_TestCase
             ->with($handlingSubject, $response);
 
         $chain = new HandlerChain(
+            $tMapFactory,
             [
                 'handler1' => 'Magento\Payment\Gateway\Response\HandlerInterface',
                 'handler2' => 'Magento\Payment\Gateway\Response\HandlerInterface'
-            ],
-            $tMapFactory
+            ]
         );
         $chain->handle($handlingSubject, $response);
     }
diff --git a/app/code/Magento/Payment/Test/Unit/Gateway/Validator/ValidatorCompositeTest.php b/app/code/Magento/Payment/Test/Unit/Gateway/Validator/ValidatorCompositeTest.php
index 8528b65ac6cecf91bd5603009334a0b47f216137..27b589b02900d45d480fc32db141e075251dad92 100644
--- a/app/code/Magento/Payment/Test/Unit/Gateway/Validator/ValidatorCompositeTest.php
+++ b/app/code/Magento/Payment/Test/Unit/Gateway/Validator/ValidatorCompositeTest.php
@@ -6,6 +6,7 @@
 namespace Magento\Payment\Test\Unit\Gateway\Validator;
 
 use Magento\Payment\Gateway\Validator\ValidatorComposite;
+use Magento\Payment\Gateway\Validator\ValidatorInterface;
 
 class ValidatorCompositeTest extends \PHPUnit_Framework_TestCase
 {
@@ -32,7 +33,7 @@ class ValidatorCompositeTest extends \PHPUnit_Framework_TestCase
                         'validator1' => 'Magento\Payment\Gateway\Validator\ValidatorInterface',
                         'validator2' => 'Magento\Payment\Gateway\Validator\ValidatorInterface'
                     ],
-                    'type' => 'Magento\Payment\Gateway\Validator\ValidatorInterface'
+                    'type' => ValidatorInterface::class
                 ]
             )
             ->willReturn($tMap);
@@ -82,11 +83,11 @@ class ValidatorCompositeTest extends \PHPUnit_Framework_TestCase
 
         $validatorComposite = new ValidatorComposite(
             $resultFactory,
+            $tMapFactory,
             [
                 'validator1' => 'Magento\Payment\Gateway\Validator\ValidatorInterface',
                 'validator2' => 'Magento\Payment\Gateway\Validator\ValidatorInterface'
-            ],
-            $tMapFactory
+            ]
         );
         static::assertSame($compositeResult, $validatorComposite->validate($validationSubject));
     }
diff --git a/app/code/Magento/Payment/Test/Unit/Gateway/Validator/ValidatorPoolTest.php b/app/code/Magento/Payment/Test/Unit/Gateway/Validator/ValidatorPoolTest.php
index becc387fab2d91b86cc6ba3b13954c8c0c29ae05..dc6ed060ab7bf2d86895d15b27a04e2d7638efcd 100644
--- a/app/code/Magento/Payment/Test/Unit/Gateway/Validator/ValidatorPoolTest.php
+++ b/app/code/Magento/Payment/Test/Unit/Gateway/Validator/ValidatorPoolTest.php
@@ -5,6 +5,7 @@
  */
 namespace Magento\Payment\Test\Unit\Gateway\Validator;
 
+use Magento\Payment\Gateway\Validator\ValidatorInterface;
 use Magento\Payment\Gateway\Validator\ValidatorPool;
 
 class ValidatorPoolTest extends \PHPUnit_Framework_TestCase
@@ -26,7 +27,7 @@ class ValidatorPoolTest extends \PHPUnit_Framework_TestCase
             ->with(
                 [
                     'array' => ['validator' => 'Magento\Payment\Gateway\Validator\ValidatorInterface'],
-                    'type' => 'Magento\Payment\Gateway\Validator\ValidatorInterface'
+                    'type' => ValidatorInterface::class
                 ]
             )
             ->willReturn($tMap);
@@ -40,8 +41,8 @@ class ValidatorPoolTest extends \PHPUnit_Framework_TestCase
             ->willReturn($commandI);
 
         $pool = new ValidatorPool(
-            ['validator' => 'Magento\Payment\Gateway\Validator\ValidatorInterface'],
-            $tMapFactory
+            $tMapFactory,
+            ['validator' => 'Magento\Payment\Gateway\Validator\ValidatorInterface']
         );
 
         static::assertSame($commandI, $pool->get('validator'));
@@ -64,7 +65,7 @@ class ValidatorPoolTest extends \PHPUnit_Framework_TestCase
             ->with(
                 [
                     'array' => [],
-                    'type' => 'Magento\Payment\Gateway\Validator\ValidatorInterface'
+                    'type' => ValidatorInterface::class
                 ]
             )
             ->willReturn($tMap);
@@ -73,7 +74,7 @@ class ValidatorPoolTest extends \PHPUnit_Framework_TestCase
             ->with('validator')
             ->willReturn(false);
 
-        $pool = new ValidatorPool([], $tMapFactory);
+        $pool = new ValidatorPool($tMapFactory, []);
         $pool->get('validator');
     }
 }
diff --git a/app/code/Magento/Payment/Test/Unit/Model/Method/LoggerTest.php b/app/code/Magento/Payment/Test/Unit/Model/Method/LoggerTest.php
index b56caf5903208f67a51713cef223b8602387a608..36cd63d8c6db69461de3d1a11b25f942cb36e505 100644
--- a/app/code/Magento/Payment/Test/Unit/Model/Method/LoggerTest.php
+++ b/app/code/Magento/Payment/Test/Unit/Model/Method/LoggerTest.php
@@ -45,6 +45,20 @@ class LoggerTest extends \PHPUnit_Framework_TestCase
         $this->logger->debug($debugData, $debugReplaceKeys, true);
     }
 
+    public function testDebugOnNoReplaceKeys()
+    {
+        $debugData =
+            [
+                'request' => ['data1' => '123', 'data2' => '123']
+            ];
+
+        $this->loggerMock->expects(static::once())
+            ->method('debug')
+            ->with(var_export($debugData, true));
+
+        $this->logger->debug($debugData, [], true);
+    }
+
     public function testDebugOff()
     {
         $debugData =
diff --git a/app/code/Magento/Translation/etc/di.xml b/app/code/Magento/Translation/etc/di.xml
index 4f8ccfd64333bf850bda4fd9653131f23ddb5100..05c7f766a452e694c648138db45d7835b9721dd2 100644
--- a/app/code/Magento/Translation/etc/di.xml
+++ b/app/code/Magento/Translation/etc/di.xml
@@ -63,22 +63,24 @@
             </argument>
         </arguments>
     </type>
+
     <type name="Magento\Framework\View\Asset\PreProcessor\Pool">
         <arguments>
-            <argument name="preProcessors" xsi:type="array">
+            <argument name="preprocessors" xsi:type="array">
                 <item name="js" xsi:type="array">
-                    <item name="js" xsi:type="array">
-                        <item name="js_translation" xsi:type="string">Magento\Translation\Model\Js\PreProcessor</item>
+                    <item name="js_translation" xsi:type="array">
+                        <item name="class" xsi:type="string">Magento\Translation\Model\Js\PreProcessor</item>
                     </item>
                 </item>
                 <item name="json" xsi:type="array">
-                    <item name="json" xsi:type="array">
-                        <item name="json_generation" xsi:type="string">Magento\Translation\Model\Json\PreProcessor</item>
+                    <item name="json_generation" xsi:type="array">
+                        <item name="class" xsi:type="string">Magento\Translation\Model\Json\PreProcessor</item>
                     </item>
                 </item>
             </argument>
         </arguments>
     </type>
+
     <type name="Magento\Framework\Console\CommandList">
         <arguments>
             <argument name="commands" xsi:type="array">
diff --git a/dev/tests/integration/testsuite/Magento/Email/Model/Template/FilterTest.php b/dev/tests/integration/testsuite/Magento/Email/Model/Template/FilterTest.php
index fbc90ac30f4c6da05143fd0391520237c2aaf580..ed282c1793d1c2d7836bee5daab7d28d371fe8c3 100644
--- a/dev/tests/integration/testsuite/Magento/Email/Model/Template/FilterTest.php
+++ b/dev/tests/integration/testsuite/Magento/Email/Model/Template/FilterTest.php
@@ -19,7 +19,7 @@ class FilterTest extends \PHPUnit_Framework_TestCase
     /**
      * @var \Magento\Email\Model\Template\Filter
      */
-    protected $model = null;
+    protected $model;
 
     /**
      * @var \Magento\TestFramework\ObjectManager
@@ -270,7 +270,7 @@ class FilterTest extends \PHPUnit_Framework_TestCase
             'File with compilation error results in error message' => [
                 TemplateTypesInterface::TYPE_HTML,
                 'file="css/file-with-error.css"',
-                \Magento\Framework\Css\PreProcessor\AdapterInterface::ERROR_MESSAGE_PREFIX,
+                \Magento\Framework\View\Asset\ContentProcessorInterface::ERROR_MESSAGE_PREFIX,
             ],
         ];
     }
@@ -356,7 +356,7 @@ class FilterTest extends \PHPUnit_Framework_TestCase
             ],
             'Developer mode - File with compilation error results in error message' => [
                 '<html><p></p> {{inlinecss file="css/file-with-error.css"}}</html>',
-                \Magento\Framework\Css\PreProcessor\AdapterInterface::ERROR_MESSAGE_PREFIX,
+                \Magento\Framework\View\Asset\ContentProcessorInterface::ERROR_MESSAGE_PREFIX,
                 false,
             ],
         ];
diff --git a/dev/tests/integration/testsuite/Magento/Framework/Css/PreProcessor/Adapter/Less/OyejorgeTest.php b/dev/tests/integration/testsuite/Magento/Framework/Css/PreProcessor/Adapter/Less/OyejorgeTest.php
deleted file mode 100644
index 399f0b7a44bfda7cde4a3623a6042edc372d3c71..0000000000000000000000000000000000000000
--- a/dev/tests/integration/testsuite/Magento/Framework/Css/PreProcessor/Adapter/Less/OyejorgeTest.php
+++ /dev/null
@@ -1,62 +0,0 @@
-<?php
-/**
- * Copyright © 2015 Magento. All rights reserved.
- * See COPYING.txt for license details.
- */
-namespace Magento\Framework\Css\PreProcessor\Adapter\Less;
-
-use Magento\Framework\App\State;
-
-/**
- * Oyejorge adapter model
- */
-class OyejorgeTest extends \PHPUnit_Framework_TestCase
-{
-    /**
-     * @var Oyejorge
-     */
-    protected $model;
-
-    /**
-     * @var \Magento\Framework\App\State
-     */
-    protected $state;
-
-    public function setUp()
-    {
-        $objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
-        $this->model = $objectManager->create('Magento\Framework\Css\PreProcessor\Adapter\Less\Oyejorge');
-        $this->state = $objectManager->get('Magento\Framework\App\State');
-    }
-
-    public function testProcess()
-    {
-        $sourceFilePath = realpath(__DIR__ . '/_files/oyejorge.less');
-        $expectedCss = ($this->state->getMode() === State::MODE_DEVELOPER)
-            ? file_get_contents(__DIR__ . '/_files/oyejorge_dev.css')
-            : file_get_contents(__DIR__ . '/_files/oyejorge.css');
-        $actualCss = ($this->model->process($sourceFilePath));
-
-        $this->assertEquals($this->cutCopyrights($expectedCss), $actualCss);
-    }
-
-    /**
-     * Cuts copyrights from css source
-     *
-     * @param string $cssSource
-     * @return string
-     */
-    private function cutCopyrights($cssSource)
-    {
-        $copyright = <<<'TAG'
-/**
- * Copyright © 2015 Magento. All rights reserved.
- * See COPYING.txt for license details.
- */
-
-
-TAG;
-        return (string)str_replace($copyright, '', $cssSource);
-
-    }
-}
diff --git a/dev/tests/integration/testsuite/Magento/Framework/Css/PreProcessor/Adapter/Less/_files/cache/lib/nested/import.less b/dev/tests/integration/testsuite/Magento/Framework/Css/PreProcessor/Adapter/Less/_files/cache/lib/nested/import.less
deleted file mode 100644
index 0b6a8af1a5130a6d19a8d976dff524408c5b15bf..0000000000000000000000000000000000000000
--- a/dev/tests/integration/testsuite/Magento/Framework/Css/PreProcessor/Adapter/Less/_files/cache/lib/nested/import.less
+++ /dev/null
@@ -1,6 +0,0 @@
-// /**
-//  * Copyright © 2015 Magento. All rights reserved.
-//  * See COPYING.txt for license details.
-//  */
-
-h1 { background-color: red; }
diff --git a/dev/tests/integration/testsuite/Magento/Framework/Css/PreProcessor/Adapter/Less/_files/cache/lib/oyejorge.less b/dev/tests/integration/testsuite/Magento/Framework/Css/PreProcessor/Adapter/Less/_files/cache/lib/oyejorge.less
deleted file mode 100644
index c71bb050df796ac1f963b2bd62a024c020f8c0c8..0000000000000000000000000000000000000000
--- a/dev/tests/integration/testsuite/Magento/Framework/Css/PreProcessor/Adapter/Less/_files/cache/lib/oyejorge.less
+++ /dev/null
@@ -1,6 +0,0 @@
-// /**
-//  * Copyright © 2015 Magento. All rights reserved.
-//  * See COPYING.txt for license details.
-//  */
-
-@import "nested/import.less";
diff --git a/dev/tests/integration/testsuite/Magento/Framework/Css/PreProcessor/Adapter/Less/_files/nested/import.less b/dev/tests/integration/testsuite/Magento/Framework/Css/PreProcessor/Adapter/Less/_files/nested/import.less
deleted file mode 100644
index 2e284b2e8eb87a22b92b769e67086265962d3822..0000000000000000000000000000000000000000
--- a/dev/tests/integration/testsuite/Magento/Framework/Css/PreProcessor/Adapter/Less/_files/nested/import.less
+++ /dev/null
@@ -1,6 +0,0 @@
-// /**
-//  * Copyright © 2015 Magento. All rights reserved.
-//  * See COPYING.txt for license details.
-//  */
-
-@body-bg-img: url(Magento_Theme::validation_advice_bg.gif);
diff --git a/dev/tests/integration/testsuite/Magento/Framework/Css/PreProcessor/Adapter/Less/_files/oyejorge.css b/dev/tests/integration/testsuite/Magento/Framework/Css/PreProcessor/Adapter/Less/_files/oyejorge.css
deleted file mode 100644
index bcf1aa406b5edaa5723cf3584be8e8896fb7cbf8..0000000000000000000000000000000000000000
--- a/dev/tests/integration/testsuite/Magento/Framework/Css/PreProcessor/Adapter/Less/_files/oyejorge.css
+++ /dev/null
@@ -1,6 +0,0 @@
-/**
- * Copyright © 2015 Magento. All rights reserved.
- * See COPYING.txt for license details.
- */
-
-#header{color: #4d926f}h2{color: #4d926f}#header{-webkit-border-radius: 5px;-moz-border-radius: 5px;-ms-border-radius: 5px;-o-border-radius: 5px;border-radius: 5px}#footer{-webkit-border-radius: 10px;-moz-border-radius: 10px;-ms-border-radius: 10px;-o-border-radius: 10px;border-radius: 10px}#header h1{font-size: 26px;font-weight: bold}#header p{font-size: 12px}#header p a{text-decoration: none}#header p a:hover{border-width: 1px}#header{color: #333;border-left: 1px;border-right: 2px}#footer{color: #141;border-color: #7d2717}body{background-image: url(Magento_Theme::validation_advice_bg.gif)}
\ No newline at end of file
diff --git a/dev/tests/integration/testsuite/Magento/Framework/Css/PreProcessor/Adapter/Less/_files/oyejorge.less b/dev/tests/integration/testsuite/Magento/Framework/Css/PreProcessor/Adapter/Less/_files/oyejorge.less
deleted file mode 100644
index 58914770c2f5de25e75cfd0fc38524fd61d31959..0000000000000000000000000000000000000000
--- a/dev/tests/integration/testsuite/Magento/Framework/Css/PreProcessor/Adapter/Less/_files/oyejorge.less
+++ /dev/null
@@ -1,74 +0,0 @@
-// /**
-//  * Copyright © 2015 Magento. All rights reserved.
-//  * See COPYING.txt for license details.
-//  */
-
-// Variables
-
-@color: #4D926F;
-
-#header {
-  color: @color;
-}
-
-h2 {
-  color: @color;
-}
-
-// Mixins
-
-.rounded-corners (@radius: 5px) {
-  -webkit-border-radius: @radius;
-  -moz-border-radius: @radius;
-  -ms-border-radius: @radius;
-  -o-border-radius: @radius;
-  border-radius: @radius;
-}
-
-#header {
-  .rounded-corners;
-}
-
-#footer {
-  .rounded-corners(10px);
-}
-
-// Nested Rules
-
-#header {
-  h1 {
-    font-size: 26px;
-    font-weight: bold;
-  }
-  p { font-size: 12px;
-    a {
-      text-decoration: none;
-      &:hover {
-        border-width: 1px;
-      }
-    }
-  }
-}
-
-// Functions & Operations
-
-@the-border: 1px;
-@base-color: #111;
-@red:        #842210;
-
-#header {
-  color: (@base-color * 3);
-  border-left: @the-border;
-  border-right: (@the-border * 2);
-}
-
-#footer {
-  color: (@base-color + #003300);
-  border-color: desaturate(@red, 10%);
-}
-
-@import "nested/import.less";
-
-body {
-  background-image: @body-bg-img;
-}
diff --git a/dev/tests/integration/testsuite/Magento/Framework/Css/PreProcessor/Adapter/Less/_files/oyejorge_dev.css b/dev/tests/integration/testsuite/Magento/Framework/Css/PreProcessor/Adapter/Less/_files/oyejorge_dev.css
deleted file mode 100644
index 0e70c6da760dbc6c5b39775e940f619daa8910db..0000000000000000000000000000000000000000
--- a/dev/tests/integration/testsuite/Magento/Framework/Css/PreProcessor/Adapter/Less/_files/oyejorge_dev.css
+++ /dev/null
@@ -1,50 +0,0 @@
-/**
- * Copyright © 2015 Magento. All rights reserved.
- * See COPYING.txt for license details.
- */
-
-#header {
-  color: #4d926f;
-}
-h2 {
-  color: #4d926f;
-}
-#header {
-  -webkit-border-radius: 5px;
-  -moz-border-radius: 5px;
-  -ms-border-radius: 5px;
-  -o-border-radius: 5px;
-  border-radius: 5px;
-}
-#footer {
-  -webkit-border-radius: 10px;
-  -moz-border-radius: 10px;
-  -ms-border-radius: 10px;
-  -o-border-radius: 10px;
-  border-radius: 10px;
-}
-#header h1 {
-  font-size: 26px;
-  font-weight: bold;
-}
-#header p {
-  font-size: 12px;
-}
-#header p a {
-  text-decoration: none;
-}
-#header p a:hover {
-  border-width: 1px;
-}
-#header {
-  color: #333333;
-  border-left: 1px;
-  border-right: 2px;
-}
-#footer {
-  color: #114411;
-  border-color: #7d2717;
-}
-body {
-  background-image: url(Magento_Theme::validation_advice_bg.gif);
-}
diff --git a/lib/internal/Magento/Framework/Css/PreProcessor/Adapter/Less/Oyejorge.php b/lib/internal/Magento/Framework/Css/PreProcessor/Adapter/Less/Oyejorge.php
deleted file mode 100644
index eed8d0555341be43c29d3fe7f05452b08ebd7783..0000000000000000000000000000000000000000
--- a/lib/internal/Magento/Framework/Css/PreProcessor/Adapter/Less/Oyejorge.php
+++ /dev/null
@@ -1,54 +0,0 @@
-<?php
-/**
- * Copyright © 2015 Magento. All rights reserved.
- * See COPYING.txt for license details.
- */
-namespace Magento\Framework\Css\PreProcessor\Adapter\Less;
-
-use Magento\Framework\App\State;
-
-/**
- * Oyejorge adapter model
- */
-class Oyejorge implements \Magento\Framework\Css\PreProcessor\AdapterInterface
-{
-    /**
-     * @var \Psr\Log\LoggerInterface
-     */
-    protected $logger;
-
-    /**
-     * @var \Magento\Framework\App\State
-     */
-    protected $appState;
-
-    /**
-     * @param \Psr\Log\LoggerInterface $logger
-     * @param State $appState
-     */
-    public function __construct(
-        \Psr\Log\LoggerInterface $logger,
-        State $appState
-    ) {
-        $this->logger = $logger;
-        $this->appState = $appState;
-    }
-
-    /**
-     * @param string $sourceFilePath
-     * @return string
-     */
-    public function process($sourceFilePath)
-    {
-        $options = ['relativeUrls' => false, 'compress' => $this->appState->getMode() !== State::MODE_DEVELOPER];
-        try {
-            $parser = new \Less_Parser($options);
-            $parser->parseFile($sourceFilePath, '');
-            return $parser->getCss();
-        } catch (\Exception $e) {
-            $errorMessage = self::ERROR_MESSAGE_PREFIX . $e->getMessage();
-            $this->logger->critical($errorMessage);
-            return $errorMessage;
-        }
-    }
-}
diff --git a/lib/internal/Magento/Framework/Css/PreProcessor/Adapter/Less/Processor.php b/lib/internal/Magento/Framework/Css/PreProcessor/Adapter/Less/Processor.php
new file mode 100644
index 0000000000000000000000000000000000000000..26cb1ce21d66a979dc2c97ba5db99db8d8d4890d
--- /dev/null
+++ b/lib/internal/Magento/Framework/Css/PreProcessor/Adapter/Less/Processor.php
@@ -0,0 +1,92 @@
+<?php
+/**
+ * Copyright © 2015 Magento. All rights reserved.
+ * See COPYING.txt for license details.
+ */
+namespace Magento\Framework\Css\PreProcessor\Adapter\Less;
+
+use Psr\Log\LoggerInterface;
+use Magento\Framework\App\State;
+use Magento\Framework\View\Asset\File;
+use Magento\Framework\View\Asset\Source;
+use Magento\Framework\Css\PreProcessor\File\Temporary;
+use Magento\Framework\View\Asset\ContentProcessorInterface;
+
+/**
+ * Class Processor
+ */
+class Processor implements ContentProcessorInterface
+{
+    /**
+     * @var LoggerInterface
+     */
+    private $logger;
+
+    /**
+     * @var State
+     */
+    private $appState;
+
+    /**
+     * @var Source
+     */
+    private $assetSource;
+
+    /**
+     * @var Temporary
+     */
+    private $temporaryFile;
+
+    /**
+     * Constructor
+     *
+     * @param LoggerInterface $logger
+     * @param State $appState
+     * @param Source $assetSource
+     * @param Temporary $temporaryFile
+     */
+    public function __construct(
+        LoggerInterface $logger,
+        State $appState,
+        Source $assetSource,
+        Temporary $temporaryFile
+    ) {
+        $this->logger = $logger;
+        $this->appState = $appState;
+        $this->assetSource = $assetSource;
+        $this->temporaryFile = $temporaryFile;
+    }
+
+    /**
+     * @inheritdoc
+     */
+    public function processContent(File $asset)
+    {
+        try {
+            $parser = new \Less_Parser(
+                [
+                    'relativeUrls' => false,
+                    'compress' => $this->appState->getMode() !== State::MODE_DEVELOPER
+                ]
+            );
+
+            $content = $this->assetSource->getContent($asset);
+
+            if (trim($content) === '') {
+                return '';
+            }
+
+            $tmpFilePath = $this->temporaryFile->createFile($asset->getPath(), $content);
+            $parser->parseFile($tmpFilePath, '');
+
+            $content = $parser->getCss();
+
+            return $content;
+        } catch (\Exception $e) {
+            $errorMessage = self::ERROR_MESSAGE_PREFIX . $e->getMessage();
+            $this->logger->critical($errorMessage);
+
+            return $errorMessage;
+        }
+    }
+}
diff --git a/lib/internal/Magento/Framework/Css/PreProcessor/AdapterInterface.php b/lib/internal/Magento/Framework/Css/PreProcessor/AdapterInterface.php
deleted file mode 100644
index b2b230bc30233add74cc614f0f820a70cd352dc4..0000000000000000000000000000000000000000
--- a/lib/internal/Magento/Framework/Css/PreProcessor/AdapterInterface.php
+++ /dev/null
@@ -1,20 +0,0 @@
-<?php
-/**
- * Copyright © 2015 Magento. All rights reserved.
- * See COPYING.txt for license details.
- */
-namespace Magento\Framework\Css\PreProcessor;
-
-/**
- * Css pre-processor adapter interface
- */
-interface AdapterInterface
-{
-    const ERROR_MESSAGE_PREFIX = 'CSS compilation from source ';
-
-    /**
-     * @param string $sourceFilePath
-     * @return string
-     */
-    public function process($sourceFilePath);
-}
diff --git a/lib/internal/Magento/Framework/Css/PreProcessor/FileGenerator.php b/lib/internal/Magento/Framework/Css/PreProcessor/FileGenerator.php
deleted file mode 100644
index ff69af61e354c142422430e601222fbacdfc8173..0000000000000000000000000000000000000000
--- a/lib/internal/Magento/Framework/Css/PreProcessor/FileGenerator.php
+++ /dev/null
@@ -1,149 +0,0 @@
-<?php
-/**
- * Copyright © 2015 Magento. All rights reserved.
- * See COPYING.txt for license details.
- */
-
-namespace Magento\Framework\Css\PreProcessor;
-
-use Magento\Framework\App\Filesystem\DirectoryList;
-use Magento\Framework\View\Asset\PreProcessor\Chain;
-use Magento\Framework\View\Asset\SourceFileGeneratorInterface;
-
-/**
- * Class FileGenerator
- * @package Magento\Framework\Css
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- */
-class FileGenerator implements SourceFileGeneratorInterface
-{
-    /**
-     * Max execution (locking) time for generation process (in seconds)
-     */
-    const MAX_LOCK_TIME = 300;
-
-    /**
-     * Lock file, if exists shows that process is locked
-     */
-    const LOCK_FILE = 'css.lock';
-
-    /**
-     * @var \Magento\Framework\Filesystem\Directory\WriteInterface
-     */
-    protected $tmpDirectory;
-
-    /**
-     * @var \Magento\Framework\View\Asset\Repository
-     */
-    private $assetRepo;
-
-    /**
-     * @var \Magento\Framework\View\Asset\Source
-     */
-    private $assetSource;
-
-    /**
-     * @var \Magento\Framework\Css\PreProcessor\Instruction\MagentoImport
-     */
-    private $magentoImportProcessor;
-
-    /**
-     * @var \Magento\Framework\Css\PreProcessor\Instruction\Import
-     */
-    private $importProcessor;
-
-    /**
-     * @var FileGenerator\RelatedGenerator
-     */
-    private $relatedGenerator;
-
-    /**
-     * @var Config
-     */
-    private $config;
-
-    /**
-     * @var File\Temporary
-     */
-    private $temporaryFile;
-
-    /**
-     * @param \Magento\Framework\Filesystem $filesystem
-     * @param \Magento\Framework\View\Asset\Repository $assetRepo
-     * @param \Magento\Framework\Css\PreProcessor\Instruction\MagentoImport $magentoImportProcessor
-     * @param \Magento\Framework\Css\PreProcessor\Instruction\Import $importProcessor
-     * @param \Magento\Framework\View\Asset\Source $assetSource
-     * @param FileGenerator\RelatedGenerator $relatedGenerator
-     * @param Config $config
-     * @param File\Temporary $temporaryFile
-     */
-    public function __construct(
-        \Magento\Framework\Filesystem $filesystem,
-        \Magento\Framework\View\Asset\Repository $assetRepo,
-        \Magento\Framework\Css\PreProcessor\Instruction\MagentoImport $magentoImportProcessor,
-        \Magento\Framework\Css\PreProcessor\Instruction\Import $importProcessor,
-        \Magento\Framework\View\Asset\Source $assetSource,
-        \Magento\Framework\Css\PreProcessor\FileGenerator\RelatedGenerator $relatedGenerator,
-        Config $config,
-        File\Temporary $temporaryFile
-    ) {
-        $this->tmpDirectory = $filesystem->getDirectoryWrite(DirectoryList::VAR_DIR);
-        $this->assetRepo = $assetRepo;
-        $this->assetSource = $assetSource;
-
-        $this->magentoImportProcessor = $magentoImportProcessor;
-        $this->importProcessor = $importProcessor;
-        $this->relatedGenerator = $relatedGenerator;
-        $this->config = $config;
-        $this->temporaryFile = $temporaryFile;
-    }
-
-    /**
-     * Create a tree of self-sustainable files and return the topmost source file,
-     * ready for passing to 3rd party library
-     *
-     * @param Chain $chain
-     * @return string Absolute path of generated topmost source file
-     */
-    public function generateFileTree(Chain $chain)
-    {
-        /**
-         * wait if generation process has already started
-         */
-        while ($this->isProcessLocked()) {
-            sleep(1);
-        }
-        $lockFilePath = $this->config->getMaterializationRelativePath() . '/' . self::LOCK_FILE;
-        $this->tmpDirectory->writeFile($lockFilePath, time());
-
-        $this->magentoImportProcessor->process($chain);
-        $this->importProcessor->process($chain);
-        $this->relatedGenerator->generate($this->importProcessor);
-
-        $contentType = $chain->getContentType();
-        $relativePath = preg_replace('#\.css$#', '.' . $contentType, $chain->getAsset()->getPath());
-        $tmpFilePath = $this->temporaryFile->createFile($relativePath, $chain->getContent());
-
-        $this->tmpDirectory->delete($lockFilePath);
-        return $tmpFilePath;
-    }
-
-    /**
-     * Check whether generation process has already locked
-     *
-     * @return bool
-     */
-    protected function isProcessLocked()
-    {
-        $lockFilePath = $this->config->getMaterializationRelativePath() . '/' . self::LOCK_FILE;
-        if ($this->tmpDirectory->isExist($lockFilePath)) {
-            $lockTime = time() - (int)$this->tmpDirectory->readFile($lockFilePath);
-            if ($lockTime >= self::MAX_LOCK_TIME) {
-                $this->tmpDirectory->delete($lockFilePath);
-                return false;
-            }
-            return true;
-        }
-        return false;
-    }
-}
diff --git a/lib/internal/Magento/Framework/Css/PreProcessor/Instruction/Import.php b/lib/internal/Magento/Framework/Css/PreProcessor/Instruction/Import.php
index 158d022f78a0ef33c07eff29d164294ab2db9c3f..2559c32270373ee30d03ab3a518a632ed27ace52 100644
--- a/lib/internal/Magento/Framework/Css/PreProcessor/Instruction/Import.php
+++ b/lib/internal/Magento/Framework/Css/PreProcessor/Instruction/Import.php
@@ -11,6 +11,7 @@ namespace Magento\Framework\Css\PreProcessor\Instruction;
 use Magento\Framework\View\Asset\LocalInterface;
 use Magento\Framework\View\Asset\NotationResolver;
 use Magento\Framework\View\Asset\PreProcessorInterface;
+use Magento\Framework\Css\PreProcessor\FileGenerator\RelatedGenerator;
 
 /**
  * @import instruction preprocessor
@@ -34,11 +35,22 @@ class Import implements PreProcessorInterface
     protected $relatedFiles = [];
 
     /**
+     * @var RelatedGenerator
+     */
+    private $relatedFileGenerator;
+
+    /**
+     * Constructor
+     *
      * @param NotationResolver\Module $notationResolver
+     * @param RelatedGenerator $relatedFileGenerator
      */
-    public function __construct(NotationResolver\Module $notationResolver)
-    {
+    public function __construct(
+        NotationResolver\Module $notationResolver,
+        RelatedGenerator $relatedFileGenerator
+    ) {
         $this->notationResolver = $notationResolver;
+        $this->relatedFileGenerator = $relatedFileGenerator;
     }
 
     /**
@@ -54,6 +66,7 @@ class Import implements PreProcessorInterface
         $content = $this->removeComments($chain->getContent());
 
         $processedContent = preg_replace_callback(self::REPLACE_PATTERN, $replaceCallback, $content);
+        $this->relatedFileGenerator->generate($this);
 
         if ($processedContent !== $content) {
             $chain->setContent($processedContent);
diff --git a/lib/internal/Magento/Framework/Css/PreProcessor/Less.php b/lib/internal/Magento/Framework/Css/PreProcessor/Less.php
deleted file mode 100644
index 4bdbbcf31a58e7093b87becf7c5dc9ab0d7cd1c6..0000000000000000000000000000000000000000
--- a/lib/internal/Magento/Framework/Css/PreProcessor/Less.php
+++ /dev/null
@@ -1,49 +0,0 @@
-<?php
-/**
- * Copyright © 2015 Magento. All rights reserved.
- * See COPYING.txt for license details.
- */
-
-namespace Magento\Framework\Css\PreProcessor;
-
-use Magento\Framework\View\Asset\PreProcessorInterface;
-
-class Less implements PreProcessorInterface
-{
-    /**
-     * @var \Magento\Framework\Css\PreProcessor\FileGenerator
-     */
-    protected $fileGenerator;
-
-    /**
-     * @var AdapterInterface
-     */
-    protected $adapter;
-
-    /**
-     * @param \Magento\Framework\Css\PreProcessor\FileGenerator $fileGenerator
-     * @param AdapterInterface $adapter
-     */
-    public function __construct(
-        \Magento\Framework\Css\PreProcessor\FileGenerator $fileGenerator,
-        AdapterInterface $adapter
-    ) {
-        $this->fileGenerator = $fileGenerator;
-        $this->adapter = $adapter;
-    }
-
-    /**
-     * {@inheritdoc}
-     */
-    public function process(\Magento\Framework\View\Asset\PreProcessor\Chain $chain)
-    {
-        $chain->setContentType('less');
-        $tmpFile = $this->fileGenerator->generateFileTree($chain);
-        $cssContent = $this->adapter->process($tmpFile);
-        $cssTrimmedContent = trim($cssContent);
-        if (!empty($cssTrimmedContent)) {
-            $chain->setContent($cssContent);
-        }
-        $chain->setContentType('css');
-    }
-}
diff --git a/lib/internal/Magento/Framework/Css/Test/Unit/PreProcessor/FileGeneratorTest.php b/lib/internal/Magento/Framework/Css/Test/Unit/PreProcessor/FileGeneratorTest.php
deleted file mode 100644
index 4f034c16360776c8e5d7344943725bfba4b4a190..0000000000000000000000000000000000000000
--- a/lib/internal/Magento/Framework/Css/Test/Unit/PreProcessor/FileGeneratorTest.php
+++ /dev/null
@@ -1,177 +0,0 @@
-<?php
-/**
- * Copyright © 2015 Magento. All rights reserved.
- * See COPYING.txt for license details.
- */
-
-namespace Magento\Framework\Css\Test\Unit\PreProcessor;
-
-class FileGeneratorTest extends \PHPUnit_Framework_TestCase
-{
-    /**
-     * @var \Magento\Framework\Css\PreProcessor\Instruction\Import|\PHPUnit_Framework_MockObject_MockObject
-     */
-    private $import;
-
-    /**
-     * @var \Magento\Framework\Css\PreProcessor\Instruction\MagentoImport|\PHPUnit_Framework_MockObject_MockObject
-     */
-    private $magentoImport;
-
-    /**
-     * @var \Magento\Framework\Filesystem\Directory\WriteInterface|\PHPUnit_Framework_MockObject_MockObject
-     */
-    private $tmpDirectory;
-
-    /**
-     * @var \Magento\Framework\Filesystem\Directory\ReadInterface|\PHPUnit_Framework_MockObject_MockObject
-     */
-    private $rootDirectory;
-
-    /**
-     * @var \Magento\Framework\View\Asset\Repository|\PHPUnit_Framework_MockObject_MockObject
-     */
-    private $assetRepo;
-
-    /**
-     * @var \Magento\Framework\Css\PreProcessor\FileGenerator
-     */
-    private $object;
-
-    /**
-     * @var \Magento\Framework\Css\PreProcessor\FileGenerator\RelatedGenerator|\PHPUnit_Framework_MockObject_MockObject
-     */
-    private $relatedGenerator;
-
-    /**
-     * @var \Magento\Framework\Css\PreProcessor\Config|\PHPUnit_Framework_MockObject_MockObject
-     */
-    private $config;
-
-    /**
-     * @var \Magento\Framework\Css\PreProcessor\File\Temporary|\PHPUnit_Framework_MockObject_MockObject
-     */
-    private $temporaryFile;
-
-    protected function setUp()
-    {
-        $this->tmpDirectory = $this->getMockForAbstractClass('Magento\Framework\Filesystem\Directory\WriteInterface');
-        $this->rootDirectory = $this->getMockForAbstractClass('Magento\Framework\Filesystem\Directory\ReadInterface');
-        $this->rootDirectory->expects($this->any())
-            ->method('getRelativePath')
-            ->will($this->returnArgument(0));
-        $this->rootDirectory->expects($this->any())
-            ->method('readFile')
-            ->will(
-                $this->returnCallback(
-                    function ($file) {
-                        return "content of '$file'";
-                    }
-                )
-            );
-        $filesystem = $this->getMock('\Magento\Framework\Filesystem', [], [], '', false);
-        $filesystem->expects($this->once())
-            ->method('getDirectoryWrite')
-            ->will($this->returnValue($this->tmpDirectory));
-        $this->assetRepo = $this->getMock('\Magento\Framework\View\Asset\Repository', [], [], '', false);
-        $this->magentoImport = $this->getMock(
-            'Magento\Framework\Css\PreProcessor\Instruction\MagentoImport',
-            [],
-            [],
-            '',
-            false
-        );
-        $this->import = $this->getMock(
-            'Magento\Framework\Css\PreProcessor\Instruction\Import',
-            [],
-            [],
-            '',
-            false
-        );
-
-        $assetSource = $this->getMock(
-            'Magento\Framework\View\Asset\Source',
-            [],
-            [],
-            '',
-            false
-        );
-
-        $this->relatedGenerator = $this->getMockBuilder(
-            'Magento\Framework\Css\PreProcessor\FileGenerator\RelatedGenerator'
-        )
-            ->disableOriginalConstructor()
-            ->setMethods([])
-            ->getMock();
-        $this->config = $this->getMockBuilder('Magento\Framework\Css\PreProcessor\Config')
-            ->disableOriginalConstructor()
-            ->setMethods([])
-            ->getMock();
-        $this->temporaryFile = $this->getMockBuilder('Magento\Framework\Css\PreProcessor\File\Temporary')
-            ->disableOriginalConstructor()
-            ->setMethods([])
-            ->getMock();
-        $this->object = new \Magento\Framework\Css\PreProcessor\FileGenerator(
-            $filesystem,
-            $this->assetRepo,
-            $this->magentoImport,
-            $this->import,
-            $assetSource,
-            $this->relatedGenerator,
-            $this->config,
-            $this->temporaryFile
-        );
-    }
-
-    public function testGenerateFileTree()
-    {
-        $lessDirectory = 'path/to/less';
-        $expectedContent = 'updated content';
-        $expectedRelativePath = 'some/file.less';
-        $expectedPath = $lessDirectory . '/some/file.less';
-
-
-        $asset = $this->getMock('Magento\Framework\View\Asset\File', [], [], '', false);
-        $chain = $this->getMock('Magento\Framework\View\Asset\PreProcessor\Chain', [], [], '', false);
-
-        $this->config->expects($this->any())
-            ->method('getLessDirectory')
-            ->willReturn($lessDirectory);
-        $this->tmpDirectory->expects($this->once())
-            ->method('isExist')
-            ->willReturn(true);
-
-        $this->magentoImport->expects($this->once())
-            ->method('process')
-            ->with($chain);
-        $this->import->expects($this->once())
-            ->method('process')
-            ->with($chain);
-        $this->relatedGenerator->expects($this->once())
-            ->method('generate')
-            ->with($this->import);
-
-        $asset->expects($this->once())
-            ->method('getPath')
-            ->will($this->returnValue('some/file.css'));
-        $chain->expects($this->once())
-            ->method('getContent')
-            ->willReturn($expectedContent);
-        $chain->expects($this->once())
-            ->method('getAsset')
-            ->willReturn($asset);
-        $chain->expects($this->once())
-            ->method('getContentType')
-            ->willReturn('less');
-
-        $this->temporaryFile->expects($this->once())
-            ->method('createFile')
-            ->with(
-                $expectedRelativePath,
-                $expectedContent
-            )
-            ->willReturn($expectedPath);
-
-        $this->assertSame($expectedPath, $this->object->generateFileTree($chain));
-    }
-}
diff --git a/lib/internal/Magento/Framework/Css/Test/Unit/PreProcessor/Instruction/ImportTest.php b/lib/internal/Magento/Framework/Css/Test/Unit/PreProcessor/Instruction/ImportTest.php
index 6be802eaf35dc19ab8238a39fa0856ae4f1eb6c6..b5959faaf5d9e016847f7f2c3c6f729941cd6fc8 100644
--- a/lib/internal/Magento/Framework/Css/Test/Unit/PreProcessor/Instruction/ImportTest.php
+++ b/lib/internal/Magento/Framework/Css/Test/Unit/PreProcessor/Instruction/ImportTest.php
@@ -8,6 +8,12 @@
 
 namespace Magento\Framework\Css\Test\Unit\PreProcessor\Instruction;
 
+use Magento\Framework\Css\PreProcessor\FileGenerator\RelatedGenerator;
+use Magento\Framework\Css\PreProcessor\Instruction\Import;
+
+/**
+ * Class ImportTest
+ */
 class ImportTest extends \PHPUnit_Framework_TestCase
 {
     /**
@@ -21,18 +27,29 @@ class ImportTest extends \PHPUnit_Framework_TestCase
     private $asset;
 
     /**
-     * @var \Magento\Framework\Css\PreProcessor\Instruction\Import
+     * @var Import
      */
     private $object;
 
+    /**
+     * @var RelatedGenerator
+     */
+    private $relatedFileGeneratorMock;
+
     protected function setUp()
     {
+
         $this->notationResolver = $this->getMock(
             '\Magento\Framework\View\Asset\NotationResolver\Module', [], [], '', false
         );
         $this->asset = $this->getMock('\Magento\Framework\View\Asset\File', [], [], '', false);
         $this->asset->expects($this->any())->method('getContentType')->will($this->returnValue('css'));
-        $this->object = new \Magento\Framework\Css\PreProcessor\Instruction\Import($this->notationResolver);
+
+        $this->relatedFileGeneratorMock = $this->getMockBuilder(RelatedGenerator::class)
+            ->disableOriginalConstructor()
+            ->getMock();
+
+        $this->object = new Import($this->notationResolver, $this->relatedFileGeneratorMock);
     }
 
     /**
diff --git a/lib/internal/Magento/Framework/Css/Test/Unit/PreProcessor/LessTest.php b/lib/internal/Magento/Framework/Css/Test/Unit/PreProcessor/LessTest.php
deleted file mode 100644
index 4b13f6d09411d4dd948f39e14d5449d374e19b58..0000000000000000000000000000000000000000
--- a/lib/internal/Magento/Framework/Css/Test/Unit/PreProcessor/LessTest.php
+++ /dev/null
@@ -1,58 +0,0 @@
-<?php
-/**
- * Copyright © 2015 Magento. All rights reserved.
- * See COPYING.txt for license details.
- */
-namespace Magento\Framework\Css\Test\Unit\PreProcessor;
-
-use Magento\Framework\View\Asset\PreProcessor\Chain;
-
-class LessTest extends \PHPUnit_Framework_TestCase
-{
-    /**
-     * @var \Magento\Framework\Css\PreProcessor\FileGenerator|\PHPUnit_Framework_MockObject_MockObject
-     */
-    private $fileGenerator;
-
-    /**
-     * @var \Magento\Framework\Css\PreProcessor\AdapterInterface|\PHPUnit_Framework_MockObject_MockObject
-     */
-    private $adapter;
-
-    /**
-     * @var Chain
-     */
-    private $chain;
-
-    /**
-     * @var \Magento\Framework\Css\PreProcessor\Less
-     */
-    private $object;
-
-    protected function setUp()
-    {
-        $this->fileGenerator = $this->getMock('\Magento\Framework\Css\PreProcessor\FileGenerator', [], [], '', false);
-        $this->adapter = $this->getMockForAbstractClass('\Magento\Framework\Css\PreProcessor\AdapterInterface');
-        $asset = $this->getMockForAbstractClass('\Magento\Framework\View\Asset\LocalInterface');
-        $asset->expects($this->once())->method('getContentType')->will($this->returnValue('origType'));
-        $this->chain = new Chain($asset, 'original content', 'origType', 'origPath');
-        $this->object = new \Magento\Framework\Css\PreProcessor\Less($this->fileGenerator, $this->adapter);
-    }
-
-    public function testProcess()
-    {
-        $expectedContent = 'updated content';
-        $tmpFile = 'tmp/file.ext';
-        $this->fileGenerator->expects($this->once())
-            ->method('generateFileTree')
-            ->with($this->chain)
-            ->will($this->returnValue($tmpFile));
-        $this->adapter->expects($this->once())
-            ->method('process')
-            ->with($tmpFile)
-            ->will($this->returnValue($expectedContent));
-        $this->object->process($this->chain);
-        $this->assertEquals($expectedContent, $this->chain->getContent());
-        $this->assertEquals('css', $this->chain->getContentType());
-    }
-}
diff --git a/lib/internal/Magento/Framework/View/Asset/ContentProcessorInterface.php b/lib/internal/Magento/Framework/View/Asset/ContentProcessorInterface.php
new file mode 100644
index 0000000000000000000000000000000000000000..a7df2aad78c42c00b8b2c96530f53e796b610ff2
--- /dev/null
+++ b/lib/internal/Magento/Framework/View/Asset/ContentProcessorInterface.php
@@ -0,0 +1,27 @@
+<?php
+/**
+ * Copyright © 2015 Magento. All rights reserved.
+ * See COPYING.txt for license details.
+ */
+namespace Magento\Framework\View\Asset;
+
+use Magento\Framework\View\Asset\File;
+
+/**
+ * Interface ContentProcessorInterface
+ */
+interface ContentProcessorInterface
+{
+    /**
+     * Error prefix
+     */
+    const ERROR_MESSAGE_PREFIX = 'Compilation from source: ';
+
+    /**
+     * Process file content
+     *
+     * @param File $asset
+     * @return string
+     */
+    public function processContent(File $asset);
+}
diff --git a/lib/internal/Magento/Framework/View/Asset/LockerProcess.php b/lib/internal/Magento/Framework/View/Asset/LockerProcess.php
new file mode 100644
index 0000000000000000000000000000000000000000..3f07c9b0ab23a1b5292f9f9b6e5ac3d46f5fde22
--- /dev/null
+++ b/lib/internal/Magento/Framework/View/Asset/LockerProcess.php
@@ -0,0 +1,111 @@
+<?php
+/**
+ * Copyright © 2015 Magento. All rights reserved.
+ * See COPYING.txt for license details.
+ */
+namespace Magento\Framework\View\Asset;
+
+use Magento\Framework\Filesystem;
+use Magento\Framework\App\Filesystem\DirectoryList;
+use Magento\Framework\Exception\FileSystemException;
+use Magento\Framework\Filesystem\Directory\WriteInterface;
+
+/**
+ * Class LockerProcess
+ */
+class LockerProcess implements LockerProcessInterface
+{
+    /**
+     * File extension lock
+     */
+    const LOCK_EXTENSION = '.lock';
+
+    /**
+     * Max execution (locking) time for process (in seconds)
+     */
+    const MAX_LOCK_TIME = 30;
+
+    /**
+     * @var Filesystem
+     */
+    private $filesystem;
+
+    /**
+     * @var string
+     */
+    private $lockFilePath;
+
+    /**
+     * @var WriteInterface
+     */
+    private $tmpDirectory;
+
+    /**
+     * Constructor
+     *
+     * @param Filesystem $filesystem
+     */
+    public function __construct(Filesystem $filesystem)
+    {
+        $this->filesystem = $filesystem;
+    }
+
+    /**
+     * @inheritdoc
+     * @throws FileSystemException
+     */
+    public function lockProcess($lockName)
+    {
+        $this->tmpDirectory = $this->filesystem->getDirectoryWrite(DirectoryList::VAR_DIR);
+        $this->lockFilePath = $this->getFilePath($lockName);
+
+        while ($this->isProcessLocked()) {
+            sleep(1);
+        }
+
+        $this->tmpDirectory->writeFile($this->lockFilePath, time());
+
+    }
+
+    /**
+     * @inheritdoc
+     * @throws FileSystemException
+     */
+    public function unlockProcess()
+    {
+        $this->tmpDirectory->delete($this->lockFilePath);
+    }
+
+    /**
+     * Check whether generation process has already locked
+     *
+     * @return bool
+     * @throws FileSystemException
+     */
+    private function isProcessLocked()
+    {
+        if ($this->tmpDirectory->isExist($this->lockFilePath)) {
+            $lockTime = (int) $this->tmpDirectory->readFile($this->lockFilePath);
+            if ((time() - $lockTime) >= self::MAX_LOCK_TIME) {
+                $this->tmpDirectory->delete($this->lockFilePath);
+
+                return false;
+            }
+
+            return true;
+        }
+
+        return false;
+    }
+
+    /**
+     * Get name of lock file
+     *
+     * @param string $name
+     * @return string
+     */
+    private function getFilePath($name)
+    {
+        return DirectoryList::TMP . DIRECTORY_SEPARATOR . $name . self::LOCK_EXTENSION;
+    }
+}
diff --git a/lib/internal/Magento/Framework/View/Asset/LockerProcessInterface.php b/lib/internal/Magento/Framework/View/Asset/LockerProcessInterface.php
new file mode 100644
index 0000000000000000000000000000000000000000..d719653a5f18d74e6592072e1acf7fa71adb8310
--- /dev/null
+++ b/lib/internal/Magento/Framework/View/Asset/LockerProcessInterface.php
@@ -0,0 +1,23 @@
+<?php
+/**
+ * Copyright © 2015 Magento. All rights reserved.
+ * See COPYING.txt for license details.
+ */
+namespace Magento\Framework\View\Asset;
+
+/**
+ * Interface LockerProcessInterface
+ */
+interface LockerProcessInterface
+{
+    /**
+     * @param string $lockName
+     * @return void
+     */
+    public function lockProcess($lockName);
+
+    /**
+     * @return void
+     */
+    public function unlockProcess();
+}
diff --git a/lib/internal/Magento/Framework/View/Asset/PreProcessor/AlternativeSource.php b/lib/internal/Magento/Framework/View/Asset/PreProcessor/AlternativeSource.php
new file mode 100644
index 0000000000000000000000000000000000000000..d727bd9fa40598dba7c3cf65330c8da88155d361
--- /dev/null
+++ b/lib/internal/Magento/Framework/View/Asset/PreProcessor/AlternativeSource.php
@@ -0,0 +1,161 @@
+<?php
+/**
+ * Copyright © 2015 Magento. All rights reserved.
+ * See COPYING.txt for license details.
+ */
+namespace Magento\Framework\View\Asset\PreProcessor;
+
+use Magento\Framework\Filesystem;
+use Magento\Framework\ObjectManagerInterface;
+use Magento\Framework\View\Asset\File\FallbackContext;
+use Magento\Framework\View\Asset\LockerProcessInterface;
+use Magento\Framework\View\Asset\ContentProcessorInterface;
+use Magento\Framework\View\Asset\PreProcessor\AlternativeSource\AssetBuilder;
+
+/**
+ * Class AlternativeSource
+ */
+class AlternativeSource implements AlternativeSourceInterface
+{
+    /**
+     * The key name of the processor class
+     */
+    const PROCESSOR_CLASS = 'class';
+
+    /**
+     * @var Helper\SortInterface
+     */
+    private $sorter;
+
+    /**
+     * @var array
+     */
+    private $alternatives;
+
+    /**
+     * @var ObjectManagerInterface
+     */
+    private $objectManager;
+
+    /**
+     * @var array
+     */
+    private $alternativesSorted;
+
+    /**
+     * @var LockerProcessInterface
+     */
+    private $lockerProcess;
+
+    /**
+     * @var string
+     */
+    private $lockName;
+
+    /**
+     * @var AssetBuilder
+     */
+    private $assetBuilder;
+
+    /**
+     * Constructor
+     *
+     * @param ObjectManagerInterface $objectManager
+     * @param LockerProcessInterface $lockerProcess
+     * @param Helper\SortInterface $sorter
+     * @param AssetBuilder $assetBuilder
+     * @param string $lockName
+     * @param array $alternatives
+     */
+    public function __construct(
+        ObjectManagerInterface $objectManager,
+        LockerProcessInterface $lockerProcess,
+        Helper\SortInterface $sorter,
+        AssetBuilder $assetBuilder,
+        $lockName,
+        array $alternatives = []
+    ) {
+        $this->objectManager = $objectManager;
+        $this->lockerProcess = $lockerProcess;
+        $this->sorter = $sorter;
+        $this->alternatives = $alternatives;
+        $this->lockName = $lockName;
+        $this->assetBuilder = $assetBuilder;
+    }
+
+    /**
+     * @inheritdoc
+     * @throws \UnexpectedValueException
+     */
+    public function process(Chain $chain)
+    {
+        $path = $chain->getAsset()->getFilePath();
+        $content = $chain->getContent();
+        if (trim($content) !== '') {
+            return;
+        }
+
+        try {
+            $this->lockerProcess->lockProcess($this->lockName . sprintf('%x', crc32($path . $content)));
+
+            $module = $chain->getAsset()->getModule();
+
+            /** @var  FallbackContext $context */
+            $context = $chain->getAsset()->getContext();
+            $chain->setContent($this->processContent($path, $content, $module, $context));
+        } finally {
+            $this->lockerProcess->unlockProcess();
+        }
+    }
+
+    /**
+     * Preparation of content for the destination file
+     *
+     * @param string $path
+     * @param string $content
+     * @param string $module
+     * @param FallbackContext $context
+     * @return string
+     * @throws \UnexpectedValueException
+     */
+    private function processContent($path, $content, $module, FallbackContext $context)
+    {
+        if ($this->alternativesSorted === null) {
+            $this->alternativesSorted = $this->sorter->sort($this->alternatives);
+        }
+
+        foreach ($this->alternativesSorted as $name => $alternative) {
+            $asset = $this->assetBuilder->setArea($context->getAreaCode())
+                ->setTheme($context->getThemePath())
+                ->setLocale($context->getLocale())
+                ->setModule($module)
+                ->setPath(preg_replace(
+                    '#\.' . preg_quote(pathinfo($path, PATHINFO_EXTENSION)) . '$#',
+                    '.' . $name,
+                    $path
+                ))->build();
+
+            $processor = $this->objectManager->get($alternative[self::PROCESSOR_CLASS]);
+            if (!$processor  instanceof ContentProcessorInterface) {
+                throw new \UnexpectedValueException(
+                    '"' . $alternative[self::PROCESSOR_CLASS] . '" has to implement the ContentProcessorInterface.'
+                );
+            }
+            $content = $processor->processContent($asset);
+
+            if (trim($content) !== '') {
+                return $content;
+            }
+        }
+
+        return $content;
+    }
+
+    /**
+     * @inheritdoc
+     */
+    public function getAlternativesExtensionsNames()
+    {
+        return array_keys($this->alternatives);
+    }
+}
diff --git a/lib/internal/Magento/Framework/View/Asset/PreProcessor/AlternativeSource/AssetBuilder.php b/lib/internal/Magento/Framework/View/Asset/PreProcessor/AlternativeSource/AssetBuilder.php
new file mode 100644
index 0000000000000000000000000000000000000000..79f13bb5632a44cb8f959d8577f22f600f9c8755
--- /dev/null
+++ b/lib/internal/Magento/Framework/View/Asset/PreProcessor/AlternativeSource/AssetBuilder.php
@@ -0,0 +1,134 @@
+<?php
+/**
+ * Copyright © 2015 Magento. All rights reserved.
+ * See COPYING.txt for license details.
+ */
+namespace Magento\Framework\View\Asset\PreProcessor\AlternativeSource;
+
+use Magento\Framework\View\Asset\File;
+use Magento\Framework\View\Asset\Repository;
+
+/**
+ * Class AssetBuilder
+ */
+class AssetBuilder
+{
+    /**
+     * @var string
+     */
+    private $area;
+
+    /**
+     * @var string
+     */
+    private $theme;
+
+    /**
+     * @var string
+     */
+    private $locale;
+
+    /**
+     * @var string
+     */
+    private $module;
+
+    /**
+     * @var string
+     */
+    private $path;
+
+    /**
+     * @var Repository
+     */
+    private $repository;
+
+    /**
+     * Constructor
+     *
+     * @param Repository $repository
+     */
+    public function __construct(Repository $repository)
+    {
+        $this->repository = $repository;
+    }
+
+    /**
+     * Set area
+     *
+     * @param string $area
+     * @return $this
+     */
+    public function setArea($area)
+    {
+        $this->area = $area;
+        return $this;
+    }
+
+    /**
+     * Set theme
+     *
+     * @param string $theme
+     * @return $this
+     */
+    public function setTheme($theme)
+    {
+        $this->theme = $theme;
+        return $this;
+    }
+
+    /**
+     * Set locale
+     *
+     * @param string $locale
+     * @return $this
+     */
+    public function setLocale($locale)
+    {
+        $this->locale = $locale;
+        return $this;
+    }
+
+    /**
+     * Set module
+     *
+     * @param string $module
+     * @return $this
+     */
+    public function setModule($module)
+    {
+        $this->module = $module;
+        return $this;
+    }
+
+    /**
+     * Set path
+     *
+     * @param string $path
+     * @return $this
+     */
+    public function setPath($path)
+    {
+        $this->path = $path;
+        return $this;
+    }
+
+    /**
+     * @return File
+     */
+    public function build()
+    {
+        $params = [
+            'area' => $this->area,
+            'theme' => $this->theme,
+            'locale' => $this->locale,
+            'module' => $this->module,
+        ];
+
+        $asset = $this->repository->createAsset($this->path, $params);
+
+        unset($this->path, $this->module, $this->locale, $this->theme, $this->area);
+
+        return $asset;
+    }
+}
diff --git a/lib/internal/Magento/Framework/View/Asset/PreProcessor/AlternativeSourceInterface.php b/lib/internal/Magento/Framework/View/Asset/PreProcessor/AlternativeSourceInterface.php
new file mode 100644
index 0000000000000000000000000000000000000000..43a20b74809449bd401fff2e119292a99910b60b
--- /dev/null
+++ b/lib/internal/Magento/Framework/View/Asset/PreProcessor/AlternativeSourceInterface.php
@@ -0,0 +1,21 @@
+<?php
+/**
+ * Copyright © 2015 Magento. All rights reserved.
+ * See COPYING.txt for license details.
+ */
+namespace Magento\Framework\View\Asset\PreProcessor;
+
+use Magento\Framework\View\Asset\PreProcessorInterface;
+
+/**
+ * Interface AlternativeSourceInterface
+ */
+interface AlternativeSourceInterface extends PreProcessorInterface
+{
+    /**
+     * Get extensions names of alternatives
+     *
+     * @return string[]
+     */
+    public function getAlternativesExtensionsNames();
+}
diff --git a/lib/internal/Magento/Framework/View/Asset/PreProcessor/Helper/Sort.php b/lib/internal/Magento/Framework/View/Asset/PreProcessor/Helper/Sort.php
new file mode 100644
index 0000000000000000000000000000000000000000..a2a4c1d8f2b5eca6f53cbdb87634a1a0e11aec4a
--- /dev/null
+++ b/lib/internal/Magento/Framework/View/Asset/PreProcessor/Helper/Sort.php
@@ -0,0 +1,72 @@
+<?php
+/**
+ * Copyright © 2015 Magento. All rights reserved.
+ * See COPYING.txt for license details.
+ */
+namespace Magento\Framework\View\Asset\PreProcessor\Helper;
+
+use Magento\Framework\Phrase;
+
+/**
+ * Class Sort
+ */
+class Sort implements SortInterface
+{
+    /**
+     * Name of directive
+     */
+    const DIRECTIVE = 'after';
+
+    /**
+     * Key of name items
+     */
+    const NEXT_KEY = 'next';
+
+    /**
+     * @var array
+     */
+    private $result;
+
+    /**
+     * @var array
+     */
+    private $array;
+
+    /**
+     * @inheritdoc
+     */
+    public function sort(array $array)
+    {
+        $this->result = [];
+        $this->array = $array;
+
+        $nodes = [];
+        $structure = [];
+        foreach ($this->array as $name => $item) {
+            $nodes[$name] = isset($nodes[$name]) ? $nodes[$name] : [self::NEXT_KEY => null];
+            if (isset($item[self::DIRECTIVE])) {
+                $nodes[$item[self::DIRECTIVE]][self::NEXT_KEY][$name] = &$nodes[$name];
+                continue;
+            }
+            $structure[$name] = &$nodes[$name];
+        }
+
+        $this->fillResult($structure);
+
+        return $this->result;
+    }
+
+    /**
+     * @param array $structure
+     * @return void
+     */
+    private function fillResult(array $structure)
+    {
+        foreach ($structure as $name => $item) {
+            $this->result[$name] = $this->array[$name];
+            if (!empty($item[self::NEXT_KEY])) {
+                $this->fillResult($item[self::NEXT_KEY]);
+            }
+        }
+    }
+}
diff --git a/lib/internal/Magento/Framework/View/Asset/PreProcessor/Helper/SortInterface.php b/lib/internal/Magento/Framework/View/Asset/PreProcessor/Helper/SortInterface.php
new file mode 100644
index 0000000000000000000000000000000000000000..130add1da0108caadbd72af45badbc56e00eb1b6
--- /dev/null
+++ b/lib/internal/Magento/Framework/View/Asset/PreProcessor/Helper/SortInterface.php
@@ -0,0 +1,23 @@
+<?php
+/**
+ * Copyright © 2015 Magento. All rights reserved.
+ * See COPYING.txt for license details.
+ */
+namespace Magento\Framework\View\Asset\PreProcessor\Helper;
+
+/**
+ * Interface SortInterface
+ */
+interface SortInterface
+{
+    /**
+     * Sorting an array by directive
+     * [
+     *     'name-1' => ['after' => 'xxx', 'data' => [...]]
+     *     'name-2' => ['after' => 'xxx', 'data' => [...]]
+     * ]
+     * @param array $array
+     * @return array
+     */
+    public function sort(array $array);
+}
diff --git a/lib/internal/Magento/Framework/View/Asset/PreProcessor/Pool.php b/lib/internal/Magento/Framework/View/Asset/PreProcessor/Pool.php
index 7a8fee000db446c8348d4442dd86bac57d57192f..ee891d96720762ffa50a6ee4edb57acf0736232a 100644
--- a/lib/internal/Magento/Framework/View/Asset/PreProcessor/Pool.php
+++ b/lib/internal/Magento/Framework/View/Asset/PreProcessor/Pool.php
@@ -14,24 +14,51 @@ use Magento\Framework\View\Asset\PreProcessorInterface;
  */
 class Pool
 {
+    const PREPROCESSOR_CLASS = 'class';
+
     /**
-     * @var ObjectManagerInterface
+     * @var array
      */
-    private $objectManager;
+    private $preprocessors;
 
     /**
      * @var array
      */
-    private $preProcessorClasses = [];
+    private $instances;
+
+    /**
+     * @var Helper\SortInterface
+     */
+    private $sorter;
+
+    /**
+     * @var string
+     */
+    private $defaultPreprocessor;
 
     /**
+     * @var ObjectManagerInterface
+     */
+    private $objectManager;
+
+    /**
+     * Constructor
+     *
      * @param ObjectManagerInterface $objectManager
-     * @param array $preProcessors
+     * @param Helper\SortInterface $sorter
+     * @param string $defaultPreprocessor
+     * @param array $preprocessors
      */
-    public function __construct(ObjectManagerInterface $objectManager, array $preProcessors = [])
-    {
+    public function __construct(
+        ObjectManagerInterface $objectManager,
+        Helper\SortInterface $sorter,
+        $defaultPreprocessor,
+        array $preprocessors = []
+    ) {
+        $this->preprocessors = $preprocessors;
+        $this->sorter = $sorter;
+        $this->defaultPreprocessor = $defaultPreprocessor;
         $this->objectManager = $objectManager;
-        $this->preProcessorClasses = $preProcessors;
     }
 
     /**
@@ -42,9 +69,8 @@ class Pool
      */
     public function process(Chain $chain)
     {
-        $fromType = $chain->getOrigContentType();
-        $toType = $chain->getTargetContentType();
-        foreach ($this->getPreProcessors($fromType, $toType) as $preProcessor) {
+        $type = $chain->getTargetContentType();
+        foreach ($this->getPreProcessors($type) as $preProcessor) {
             $preProcessor->process($chain);
         }
     }
@@ -52,28 +78,35 @@ class Pool
     /**
      * Retrieve preProcessors by types
      *
-     * @param string $fromType
-     * @param string $toType
+     * @param string $type
      * @return PreProcessorInterface[]
+     * @throws \UnexpectedValueException
      */
-    private function getPreProcessors($fromType, $toType)
+    private function getPreProcessors($type)
     {
-        $preProcessors = [];
-        if (isset($this->preProcessorClasses[$fromType]) && isset($this->preProcessorClasses[$fromType][$toType])) {
-            $preProcessors = $this->preProcessorClasses[$fromType][$toType];
+        if (isset($this->instances[$type])) {
+            return $this->instances[$type];
+        }
+
+        if (isset($this->preprocessors[$type])) {
+            $preprocessors = $this->sorter->sort($this->preprocessors[$type]);
         } else {
-            $preProcessors[] = 'Magento\Framework\View\Asset\PreProcessor\Passthrough';
+            $preprocessors = [
+                'default' => [self::PREPROCESSOR_CLASS => $this->defaultPreprocessor]
+            ];
         }
 
-        $processorInstances = [];
-        foreach ($preProcessors as $preProcessor) {
-            $processorInstance = $this->objectManager->get($preProcessor);
-            if (!$processorInstance instanceof PreProcessorInterface) {
-                throw new \UnexpectedValueException("{$preProcessor} has to implement the PreProcessorInterface.");
+        $this->instances[$type] = [];
+        foreach ($preprocessors as $preprocessor) {
+            $instance = $this->objectManager->get($preprocessor[self::PREPROCESSOR_CLASS]);
+            if (!$instance instanceof PreProcessorInterface) {
+                throw new \UnexpectedValueException(
+                    '"' . $preprocessor[self::PREPROCESSOR_CLASS] . '" has to implement the PreProcessorInterface.'
+                );
             }
-            $processorInstances[] = $processorInstance;
+            $this->instances[$type][] = $instance;
         }
 
-        return $processorInstances;
+        return $this->instances[$type];
     }
 }
diff --git a/lib/internal/Magento/Framework/View/Design/FileResolution/Fallback/Resolver/Alternative.php b/lib/internal/Magento/Framework/View/Design/FileResolution/Fallback/Resolver/Alternative.php
index f943656b1cd92a2a0da9803d84a129a3593b3c6e..c8872027ad2af919f455ca7afd7fe3801e6dc9b6 100644
--- a/lib/internal/Magento/Framework/View/Design/FileResolution/Fallback/Resolver/Alternative.php
+++ b/lib/internal/Magento/Framework/View/Design/FileResolution/Fallback/Resolver/Alternative.php
@@ -30,7 +30,7 @@ class Alternative extends Simple
     public function __construct(
         Filesystem $filesystem,
         \Magento\Framework\View\Design\Fallback\RulePool $rulePool,
-        array $alternativeExtensions
+        array $alternativeExtensions = []
     ) {
         foreach ($alternativeExtensions as $extension => $newExtensions) {
             if (!is_string($extension) || !is_array($newExtensions)) {
diff --git a/lib/internal/Magento/Framework/View/Test/Unit/Asset/LockerProcessTest.php b/lib/internal/Magento/Framework/View/Test/Unit/Asset/LockerProcessTest.php
new file mode 100644
index 0000000000000000000000000000000000000000..8cd6a99610b09619e3d3feb14c779065757e7ffd
--- /dev/null
+++ b/lib/internal/Magento/Framework/View/Test/Unit/Asset/LockerProcessTest.php
@@ -0,0 +1,155 @@
+<?php
+/**
+ * Copyright © 2015 Magento. All rights reserved.
+ * See COPYING.txt for license details.
+ */
+namespace Magento\Framework\View\Test\Unit\Asset;
+
+use Magento\Framework\Filesystem;
+use Magento\Framework\View\Asset\LockerProcess;
+use Magento\Framework\App\Filesystem\DirectoryList;
+use Magento\Framework\Filesystem\Directory\WriteInterface;
+
+/**
+ * Class LockerProcessTest
+ *
+ * @see \Magento\Framework\View\Asset\LockerProcess
+ */
+class LockerProcessTest extends \PHPUnit_Framework_TestCase
+{
+    const LOCK_NAME = 'test-lock';
+
+    /**
+     * @var string
+     */
+    private $fileName;
+
+    /**
+     * @var LockerProcess
+     */
+    private $lockerProcess;
+
+    /**
+     * @var Filesystem|\PHPUnit_Framework_MockObject_MockObject
+     */
+    private $filesystemMock;
+
+    /**
+     * Set up
+     */
+    protected function setUp()
+    {
+        $this->fileName = DirectoryList::TMP . DIRECTORY_SEPARATOR . self::LOCK_NAME . LockerProcess::LOCK_EXTENSION;
+
+        $this->filesystemMock = $this->getMockBuilder('Magento\Framework\Filesystem')
+            ->disableOriginalConstructor()
+            ->getMock();
+
+        $this->lockerProcess = new LockerProcess($this->filesystemMock);
+    }
+
+    /**
+     * Test for lockProcess method
+     *
+     * @param string $method
+     *
+     * @dataProvider dataProviderTestLockProcess
+     */
+    public function testLockProcess($method)
+    {
+        $this->filesystemMock->expects(self::once())
+            ->method('getDirectoryWrite')
+            ->with(DirectoryList::VAR_DIR)
+            ->willReturn($this->$method());
+
+        $this->lockerProcess->lockProcess(self::LOCK_NAME);
+    }
+
+    /**
+     * Test for unlockProcess method
+     */
+    public function testUnlockProcess()
+    {
+        $this->filesystemMock->expects(self::once())
+            ->method('getDirectoryWrite')
+            ->with(DirectoryList::VAR_DIR)
+            ->willReturn($this->getTmpDirectoryMockFalse(1));
+
+        $this->lockerProcess->lockProcess(self::LOCK_NAME);
+        $this->lockerProcess->unlockProcess();
+    }
+
+    /**
+     * @return array
+     */
+    public function dataProviderTestLockProcess()
+    {
+        return [
+            ['method' => 'getTmpDirectoryMockTrue'],
+            ['method' => 'getTmpDirectoryMockFalse']
+        ];
+    }
+
+    /**
+     * @return WriteInterface|\PHPUnit_Framework_MockObject_MockObject
+     */
+    protected function getTmpDirectoryMockTrue()
+    {
+        $tmpDirectoryMock = $this->getTmpDirectoryMock();
+
+        $tmpDirectoryMock->expects(self::atLeastOnce())
+            ->method('isExist')
+            ->with($this->fileName)
+            ->willReturn(true);
+
+        $tmpDirectoryMock->expects(self::atLeastOnce())
+            ->method('readFile')
+            ->with($this->fileName)
+            ->willReturn(time() - 25);
+
+
+        $tmpDirectoryMock->expects(self::once())
+            ->method('writeFile')
+            ->with($this->fileName, self::matchesRegularExpression('#\d+#'));
+
+        return $tmpDirectoryMock;
+    }
+
+    /**
+     * @param int $exactly
+     * @return WriteInterface|\PHPUnit_Framework_MockObject_MockObject
+     */
+    protected function getTmpDirectoryMockFalse($exactly = 0)
+    {
+        $tmpDirectoryMock = $this->getTmpDirectoryMock();
+
+        $tmpDirectoryMock->expects(self::atLeastOnce())
+            ->method('isExist')
+            ->with($this->fileName)
+            ->willReturn(false);
+
+        $tmpDirectoryMock->expects(self::never())
+            ->method('readFile');
+
+        $tmpDirectoryMock->expects(self::exactly($exactly))
+            ->method('delete')
+            ->with($this->fileName);
+
+        $tmpDirectoryMock->expects(self::once())
+            ->method('writeFile')
+            ->with($this->fileName, self::matchesRegularExpression('#\d+#'));
+
+        return $tmpDirectoryMock;
+    }
+
+    /**
+     * @return WriteInterface|\PHPUnit_Framework_MockObject_MockObject
+     */
+    private function getTmpDirectoryMock()
+    {
+        $tmpDirectoryMock = $this->getMockBuilder('Magento\Framework\Filesystem\Directory\WriteInterface')
+            ->getMockForAbstractClass();
+
+        return $tmpDirectoryMock;
+    }
+}
diff --git a/lib/internal/Magento/Framework/View/Test/Unit/Asset/PreProcessor/Adapter/Less/ProcessorTest.php b/lib/internal/Magento/Framework/View/Test/Unit/Asset/PreProcessor/Adapter/Less/ProcessorTest.php
new file mode 100644
index 0000000000000000000000000000000000000000..5989389bdd2d50b3d2137e62a84801845ee6a33d
--- /dev/null
+++ b/lib/internal/Magento/Framework/View/Test/Unit/Asset/PreProcessor/Adapter/Less/ProcessorTest.php
@@ -0,0 +1,185 @@
+<?php
+/**
+ * Copyright © 2015 Magento. All rights reserved.
+ * See COPYING.txt for license details.
+ */
+namespace Magento\Framework\View\Test\Unit\Asset\PreProcessor\Adapter\Less;
+
+use Psr\Log\LoggerInterface;
+use Magento\Framework\App\State;
+use Magento\Framework\View\Asset\File;
+use Magento\Framework\View\Asset\Source;
+use Magento\Framework\Css\PreProcessor\File\Temporary;
+use Magento\Framework\Css\PreProcessor\Adapter\Less\Processor;
+
+/**
+ * Class ProcessorTest
+ */
+class ProcessorTest extends \PHPUnit_Framework_TestCase
+{
+    const TEST_CONTENT = 'test-content';
+
+    const ASSET_PATH = 'test-path';
+
+    const TMP_PATH_LESS = '_file/test.less';
+
+    const TMP_PATH_CSS = '_file/test.css';
+
+    const ERROR_MESSAGE = 'Test exception';
+
+    /**
+     * @var Processor
+     */
+    private $processor;
+
+    /**
+     * @var LoggerInterface|\PHPUnit_Framework_MockObject_MockObject
+     */
+    private $loggerMock;
+
+    /**
+     * @var State|\PHPUnit_Framework_MockObject_MockObject
+     */
+    private $appStateMock;
+
+    /**
+     * @var Source|\PHPUnit_Framework_MockObject_MockObject
+     */
+    private $assetSourceMock;
+
+    /**
+     * @var Temporary|\PHPUnit_Framework_MockObject_MockObject
+     */
+    private $temporaryFileMock;
+
+    /**
+     * Set up
+     */
+    protected function setUp()
+    {
+        $this->loggerMock = $this->getMockBuilder('Psr\Log\LoggerInterface')
+            ->getMockForAbstractClass();
+        $this->appStateMock = $this->getMockBuilder('Magento\Framework\App\State')
+            ->disableOriginalConstructor()
+            ->getMock();
+        $this->assetSourceMock = $this->getMockBuilder('Magento\Framework\View\Asset\Source')
+            ->disableOriginalConstructor()
+            ->getMock();
+        $this->temporaryFileMock = $this->getMockBuilder('Magento\Framework\Css\PreProcessor\File\Temporary')
+            ->disableOriginalConstructor()
+            ->getMock();
+
+        $this->processor = new Processor(
+            $this->loggerMock,
+            $this->appStateMock,
+            $this->assetSourceMock,
+            $this->temporaryFileMock
+        );
+    }
+
+    /**
+     * Test for processContent method (exception)
+     */
+    public function testProcessContentException()
+    {
+        $assetMock = $this->getAssetMock();
+
+        $this->appStateMock->expects(self::once())
+            ->method('getMode')
+            ->willReturn(State::MODE_DEVELOPER);
+
+        $this->assetSourceMock->expects(self::once())
+            ->method('getContent')
+            ->with($assetMock)
+            ->willThrowException(new \Exception(self::ERROR_MESSAGE));
+
+        $this->loggerMock->expects(self::once())
+            ->method('critical')
+            ->with(Processor::ERROR_MESSAGE_PREFIX . self::ERROR_MESSAGE);
+
+        $this->temporaryFileMock->expects(self::never())
+            ->method('createFile');
+
+        $assetMock->expects(self::never())
+            ->method('getPath');
+
+        $content = $this->processor->processContent($assetMock);
+
+        self::assertEquals(Processor::ERROR_MESSAGE_PREFIX . self::ERROR_MESSAGE, $content);
+    }
+
+    /**
+     * Test for processContent method (empty content)
+     */
+    public function testProcessContentEmpty()
+    {
+        $assetMock = $this->getAssetMock();
+
+        $this->appStateMock->expects(self::once())
+            ->method('getMode')
+            ->willReturn(State::MODE_DEVELOPER);
+
+        $this->assetSourceMock->expects(self::once())
+            ->method('getContent')
+            ->with($assetMock)
+            ->willReturn('');
+
+        $this->temporaryFileMock->expects(self::never())
+            ->method('createFile');
+
+        $assetMock->expects(self::never())
+            ->method('getPath');
+
+        $this->loggerMock->expects(self::never())
+            ->method('critical');
+
+        $this->processor->processContent($assetMock);
+    }
+
+    /**
+     * Test for processContent method (not empty content)
+     */
+    public function testProcessContentNotEmpty()
+    {
+        $assetMock = $this->getAssetMock();
+
+        $this->appStateMock->expects(self::once())
+            ->method('getMode')
+            ->willReturn(State::MODE_DEVELOPER);
+
+        $this->assetSourceMock->expects(self::once())
+            ->method('getContent')
+            ->with($assetMock)
+            ->willReturn(self::TEST_CONTENT);
+
+        $this->temporaryFileMock->expects(self::once())
+            ->method('createFile')
+            ->with(self::ASSET_PATH, self::TEST_CONTENT)
+            ->willReturn(__DIR__ . '/' . self::TMP_PATH_LESS);
+
+        $assetMock->expects(self::once())
+            ->method('getPath')
+            ->willReturn(self::ASSET_PATH);
+
+        $this->loggerMock->expects(self::never())
+            ->method('critical');
+
+        $clearSymbol = ["\n", "\r", "\t", ' '];
+        self::assertEquals(
+            trim(str_replace($clearSymbol, '', file_get_contents(__DIR__ . '/' . self::TMP_PATH_CSS))),
+            trim(str_replace($clearSymbol, '', $this->processor->processContent($assetMock)))
+        );
+    }
+
+    /**
+     * @return File|\PHPUnit_Framework_MockObject_MockObject
+     */
+    private function getAssetMock()
+    {
+        $assetMock = $this->getMockBuilder('Magento\Framework\View\Asset\File')
+            ->disableOriginalConstructor()
+            ->getMock();
+
+        return $assetMock;
+    }
+}
diff --git a/lib/internal/Magento/Framework/View/Test/Unit/Asset/PreProcessor/Adapter/Less/_file/test.css b/lib/internal/Magento/Framework/View/Test/Unit/Asset/PreProcessor/Adapter/Less/_file/test.css
new file mode 100644
index 0000000000000000000000000000000000000000..7c30a79a3a75110b9504ce41bbcbc33155284668
--- /dev/null
+++ b/lib/internal/Magento/Framework/View/Test/Unit/Asset/PreProcessor/Adapter/Less/_file/test.css
@@ -0,0 +1,19 @@
+/**
+ * Copyright © 2015 Magento. All rights reserved.
+ * See COPYING.txt for license details.
+ */
+body {
+   background: #333333;
+   color: #454545;
+}
+a {
+   color: #ff9900;
+}
+h1,
+h2,
+h3,
+h4,
+h5,
+h6 {
+   color: #333333;
+}
diff --git a/lib/internal/Magento/Framework/View/Test/Unit/Asset/PreProcessor/Adapter/Less/_file/test.less b/lib/internal/Magento/Framework/View/Test/Unit/Asset/PreProcessor/Adapter/Less/_file/test.less
new file mode 100644
index 0000000000000000000000000000000000000000..6ecc83aa9dae673f78e64c3c43423b852505e0be
--- /dev/null
+++ b/lib/internal/Magento/Framework/View/Test/Unit/Asset/PreProcessor/Adapter/Less/_file/test.less
@@ -0,0 +1,19 @@
+/**
+ * Copyright © 2015 Magento. All rights reserved.
+ * See COPYING.txt for license details.
+ */
+@color-orange: #ff9900;
+@color-gray_light: #cccccc;
+@color-black_dark: #333333;
+@color-black_medium: #454545;
+
+body {
+  background: @color-black_dark;
+  color: @color-black_medium;
+}
+a {
+  color:@color-orange;
+}
+h1, h2, h3, h4, h5, h6 {
+  color: @color-black_dark;
+}
\ No newline at end of file
diff --git a/lib/internal/Magento/Framework/View/Test/Unit/Asset/PreProcessor/AlternativeSourceTest.php b/lib/internal/Magento/Framework/View/Test/Unit/Asset/PreProcessor/AlternativeSourceTest.php
new file mode 100644
index 0000000000000000000000000000000000000000..2c3591ffbb6f294f5d52757121de9bbb00b2158f
--- /dev/null
+++ b/lib/internal/Magento/Framework/View/Test/Unit/Asset/PreProcessor/AlternativeSourceTest.php
@@ -0,0 +1,363 @@
+<?php
+/**
+ * Copyright © 2015 Magento. All rights reserved.
+ * See COPYING.txt for license details.
+ */
+namespace Magento\Framework\View\Test\Unit\Asset\PreProcessor;
+
+use Magento\Framework\Filesystem;
+use Magento\Framework\View\Asset\File;
+use Magento\Framework\ObjectManagerInterface;
+use Magento\Framework\View\Asset\LocalInterface;
+use Magento\Framework\View\Asset\PreProcessor\Chain;
+use Magento\Framework\View\Asset\File\FallbackContext;
+use Magento\Framework\View\Asset\LockerProcessInterface;
+use Magento\Framework\View\Asset\ContentProcessorInterface;
+use Magento\Framework\View\Asset\PreProcessor\AlternativeSource;
+use Magento\Framework\View\Asset\PreProcessor\Helper\SortInterface;
+use Magento\Framework\View\Asset\PreProcessor\AlternativeSource\AssetBuilder;
+
+/**
+ * Class AlternativeSourceTest
+ *
+ * @see \Magento\Framework\View\Asset\PreProcessor\AlternativeSource
+ */
+class AlternativeSourceTest extends \PHPUnit_Framework_TestCase
+{
+    const AREA = 'test-area';
+
+    const THEME = 'test-theme';
+
+    const LOCALE = 'test-locale';
+
+    const FILE_PATH = 'test-file';
+
+    const MODULE = 'test-module';
+
+    const NEW_CONTENT = 'test-new-content';
+
+    /**
+     * @var SortInterface|\PHPUnit_Framework_MockObject_MockObject
+     */
+    private $sorterMock;
+
+    /**
+     * @var ObjectManagerInterface|\PHPUnit_Framework_MockObject_MockObject
+     */
+    private $objectManagerMock;
+
+    /**
+     * @var LockerProcessInterface|\PHPUnit_Framework_MockObject_MockObject
+     */
+    private $lockerProcessMock;
+
+    /**
+     * @var AssetBuilder|\PHPUnit_Framework_MockObject_MockObject
+     */
+    private $assetBuilderMock;
+
+    /**
+     * @var ContentProcessorInterface|\PHPUnit_Framework_MockObject_MockObject
+     */
+    private $alternativeMock;
+
+    /**
+     * Set up
+     */
+    protected function setUp()
+    {
+        $this->sorterMock = $this->getMockBuilder('Magento\Framework\View\Asset\PreProcessor\Helper\SortInterface')
+            ->getMockForAbstractClass();
+        $this->objectManagerMock = $this->getMockBuilder('Magento\Framework\ObjectManagerInterface')
+            ->getMockForAbstractClass();
+        $this->lockerProcessMock = $this->getMockBuilder('Magento\Framework\View\Asset\LockerProcessInterface')
+            ->getMockForAbstractClass();
+        $this->assetBuilderMock = $this->getMockBuilder(
+            'Magento\Framework\View\Asset\PreProcessor\AlternativeSource\AssetBuilder'
+        )->disableOriginalConstructor()
+            ->getMock();
+        $this->alternativeMock = $this->getMockBuilder('Magento\Framework\View\Asset\ContentProcessorInterface')
+            ->getMockForAbstractClass();
+    }
+
+    /**
+     * Run test for process method (exception)
+     */
+    public function testProcessException()
+    {
+        $alternatives = [
+            'processor' => [
+                AlternativeSource::PROCESSOR_CLASS => 'stdClass'
+            ]
+        ];
+
+        $this->lockerProcessMock->expects(self::once())
+            ->method('lockProcess')
+            ->with(self::isType('string'));
+        $this->lockerProcessMock->expects(self::once())
+            ->method('unlockProcess');
+
+        $this->sorterMock->expects(self::once())
+            ->method('sort')
+            ->with($alternatives)
+            ->willReturn($alternatives);
+
+        $this->assetBuilderMock->expects(self::once())
+            ->method('setArea')
+            ->with(self::AREA)
+            ->willReturnSelf();
+        $this->assetBuilderMock->expects(self::once())
+            ->method('setTheme')
+            ->with(self::THEME)
+            ->willReturnSelf();
+        $this->assetBuilderMock->expects(self::once())
+            ->method('setLocale')
+            ->with(self::LOCALE)
+            ->willReturnSelf();
+        $this->assetBuilderMock->expects(self::once())
+            ->method('setModule')
+            ->with(self::MODULE)
+            ->willReturnSelf();
+        $this->assetBuilderMock->expects(self::once())
+            ->method('setPath')
+            ->with(self::FILE_PATH)
+            ->willReturnSelf();
+        $this->assetBuilderMock->expects(self::once())
+            ->method('build')
+            ->willReturn($this->getAssetNew());
+
+        $this->objectManagerMock->expects(self::once())
+            ->method('get')
+            ->with('stdClass')
+            ->willReturn(new \stdClass());
+
+        $alternativeSource = new AlternativeSource(
+            $this->objectManagerMock,
+            $this->lockerProcessMock,
+            $this->sorterMock,
+            $this->assetBuilderMock,
+            'lock',
+            $alternatives
+        );
+        try {
+            $alternativeSource->process($this->getChainMockExpects('', 0));
+        } catch (\UnexpectedValueException $e) {
+            self::assertInstanceOf('\UnexpectedValueException', $e);
+        }
+    }
+
+    /**
+     * Run test for process method
+     */
+    public function testProcess()
+    {
+        $alternatives = [
+            'processor' => [
+                AlternativeSource::PROCESSOR_CLASS => 'Magento\Framework\View\Asset\ContentProcessorInterface'
+            ]
+        ];
+
+        $this->lockerProcessMock->expects(self::once())
+            ->method('lockProcess')
+            ->with(self::isType('string'));
+        $this->lockerProcessMock->expects(self::once())
+            ->method('unlockProcess');
+
+        $this->sorterMock->expects(self::once())
+            ->method('sort')
+            ->with($alternatives)
+            ->willReturn($alternatives);
+
+        $assetMock = $this->getAssetNew();
+
+        $this->assetBuilderMock->expects(self::once())
+            ->method('setArea')
+            ->with(self::AREA)
+            ->willReturnSelf();
+        $this->assetBuilderMock->expects(self::once())
+            ->method('setTheme')
+            ->with(self::THEME)
+            ->willReturnSelf();
+        $this->assetBuilderMock->expects(self::once())
+            ->method('setLocale')
+            ->with(self::LOCALE)
+            ->willReturnSelf();
+        $this->assetBuilderMock->expects(self::once())
+            ->method('setModule')
+            ->with(self::MODULE)
+            ->willReturnSelf();
+        $this->assetBuilderMock->expects(self::once())
+            ->method('setPath')
+            ->with(self::FILE_PATH)
+            ->willReturnSelf();
+        $this->assetBuilderMock->expects(self::once())
+            ->method('build')
+            ->willReturn($assetMock);
+
+        $this->objectManagerMock->expects(self::once())
+            ->method('get')
+            ->with('Magento\Framework\View\Asset\ContentProcessorInterface')
+            ->willReturn($this->getProcessorMock($assetMock));
+
+        $alternativeSource = new AlternativeSource(
+            $this->objectManagerMock,
+            $this->lockerProcessMock,
+            $this->sorterMock,
+            $this->assetBuilderMock,
+            'lock',
+            $alternatives
+        );
+
+        $alternativeSource->process($this->getChainMockExpects());
+    }
+
+    /**
+     * Run test for process method (content not empty)
+     */
+    public function testProcessContentNotEmpty()
+    {
+        $chainMock = $this->getChainMock();
+        $assetMock = $this->getAssetMock();
+
+        $chainMock->expects(self::once())
+            ->method('getContent')
+            ->willReturn('test-content');
+
+        $chainMock->expects(self::once())
+            ->method('getAsset')
+            ->willReturn($assetMock);
+
+        $this->lockerProcessMock->expects(self::never())
+            ->method('lockProcess');
+        $this->lockerProcessMock->expects(self::never())
+            ->method('unlockProcess');
+
+        $alternativeSource = new AlternativeSource(
+            $this->objectManagerMock,
+            $this->lockerProcessMock,
+            $this->sorterMock,
+            $this->assetBuilderMock,
+            'lock',
+            []
+        );
+
+        $alternativeSource->process($chainMock);
+    }
+
+    /**
+     * @param \PHPUnit_Framework_MockObject_MockObject $asset
+     * @return ContentProcessorInterface|\PHPUnit_Framework_MockObject_MockObject
+     */
+    private function getProcessorMock($asset)
+    {
+        $processorMock = $this->getMockBuilder('Magento\Framework\View\Asset\ContentProcessorInterface')
+            ->getMockForAbstractClass();
+
+        $processorMock->expects(self::once())
+            ->method('processContent')
+            ->with($asset)
+            ->willReturn(self::NEW_CONTENT);
+
+        return $processorMock;
+    }
+
+    /**
+     * @return Chain|\PHPUnit_Framework_MockObject_MockObject
+     */
+    private function getChainMock()
+    {
+        $chainMock = $this->getMockBuilder('Magento\Framework\View\Asset\PreProcessor\Chain')
+            ->disableOriginalConstructor()
+            ->getMock();
+
+        return $chainMock;
+    }
+
+    /**
+     * @param string $content
+     * @param int $contentExactly
+     * @return Chain|\PHPUnit_Framework_MockObject_MockObject
+     */
+    private function getChainMockExpects($content = '', $contentExactly = 1)
+    {
+        $chainMock = $this->getChainMock();
+
+        $chainMock->expects(self::once())
+            ->method('getContent')
+            ->willReturn($content);
+        $chainMock->expects(self::exactly(3))
+            ->method('getAsset')
+            ->willReturn($this->getAssetMockExpects());
+        $chainMock->expects(self::exactly($contentExactly))
+            ->method('setContent')
+            ->willReturn(self::NEW_CONTENT);
+
+        return $chainMock;
+    }
+
+    /**
+     * @return File|\PHPUnit_Framework_MockObject_MockObject
+     */
+    private function getAssetNew()
+    {
+        $assetMock = $this->getMockBuilder('Magento\Framework\View\Asset\File')
+            ->disableOriginalConstructor()
+            ->getMock();
+
+        return $assetMock;
+    }
+
+    /**
+     * @return LocalInterface|\PHPUnit_Framework_MockObject_MockObject
+     */
+    private function getAssetMock()
+    {
+        $assetMock = $this->getMockBuilder('Magento\Framework\View\Asset\LocalInterface')
+            ->disableOriginalConstructor()
+            ->getMock();
+
+        return $assetMock;
+    }
+
+    /**
+     * @return LocalInterface|\PHPUnit_Framework_MockObject_MockObject
+     */
+    private function getAssetMockExpects()
+    {
+        $assetMock = $this->getAssetMock();
+
+        $assetMock->expects(self::once())
+            ->method('getContext')
+            ->willReturn($this->getContextMock());
+        $assetMock->expects(self::once())
+            ->method('getFilePath')
+            ->willReturn(self::FILE_PATH);
+        $assetMock->expects(self::once())
+            ->method('getModule')
+            ->willReturn(self::MODULE);
+
+        return $assetMock;
+    }
+
+    /**
+     * @return FallbackContext|\PHPUnit_Framework_MockObject_MockObject
+     */
+    private function getContextMock()
+    {
+        $contextMock = $this->getMockBuilder('Magento\Framework\View\Asset\File\FallbackContext')
+            ->disableOriginalConstructor()
+            ->getMock();
+
+        $contextMock->expects(self::once())
+            ->method('getAreaCode')
+            ->willReturn(self::AREA);
+        $contextMock->expects(self::once())
+            ->method('getThemePath')
+            ->willReturn(self::THEME);
+        $contextMock->expects(self::once())
+            ->method('getLocale')
+            ->willReturn(self::LOCALE);
+
+        return $contextMock;
+    }
+}
diff --git a/lib/internal/Magento/Framework/View/Test/Unit/Asset/PreProcessor/Helper/SortTest.php b/lib/internal/Magento/Framework/View/Test/Unit/Asset/PreProcessor/Helper/SortTest.php
new file mode 100644
index 0000000000000000000000000000000000000000..35e043143266047e8ec3e579409ab0a1ce1f9713
--- /dev/null
+++ b/lib/internal/Magento/Framework/View/Test/Unit/Asset/PreProcessor/Helper/SortTest.php
@@ -0,0 +1,195 @@
+<?php
+/**
+ * Copyright © 2015 Magento. All rights reserved.
+ * See COPYING.txt for license details.
+ */
+namespace Magento\Framework\View\Test\Unit\Asset\PreProcessor\Helper;
+
+use Magento\Framework\View\Asset\PreProcessor\Helper\Sort;
+
+/**
+ * Class SortTest
+ *
+ * @see \Magento\Framework\View\Asset\PreProcessor\Helper\Sorter2
+ */
+class SortTest extends \PHPUnit_Framework_TestCase
+{
+    /**
+     * @param array $arrayData
+     * @param array $expected
+     *
+     * @dataProvider dataProviderTestSorting
+     */
+    public function testSorting(array $arrayData, array $expected, $message)
+    {
+        $sorter = new Sort();
+
+        $result = $sorter->sort($arrayData);
+
+        static::assertEquals($expected, array_keys($result), $message);
+    }
+
+    /**
+     * @return array
+     *
+     * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
+     */
+    public function dataProviderTestSorting()
+    {
+        return [
+            [
+                'arrayData' => [
+                    'name-1' => [ // 2
+                        'after' => 'name-3',
+                        'processor' => new \stdClass()
+                    ],
+                    'name-2' => [ // 0
+                        'processor' => new \stdClass()
+                    ],
+                    'name-3' => [ // 1
+                        'after' => 'name-2',
+                        'processor' => new \stdClass()
+                    ],
+                ],
+                'expected' => [
+                    'name-2', 'name-3', 'name-1'
+                ],
+                'message' => 'variation-1',
+            ],
+            [
+                'arrayData' => [
+                    'name-1' => [ // 3
+                        'after' => 'name-6',
+                        'processor' => new \stdClass()
+                    ],
+                    'name-2' => [ // 1
+                        'processor' => new \stdClass()
+                    ],
+                    'name-3' => [ // 6
+                        'after' => 'name-5',
+                        'processor' => new \stdClass()
+                    ],
+                    'name-4' => [ // 4
+                        'after' => 'name-1',
+                        'processor' => new \stdClass()
+                    ],
+                    'name-5' => [ // 5
+                        'after' => 'name-4',
+                        'processor' => new \stdClass()
+                    ],
+                    'name-6' => [ // 2
+                        'after' => 'name-2',
+                        'processor' => new \stdClass()
+                    ],
+                ],
+                'expected' => [
+                    'name-2', 'name-6', 'name-1', 'name-4', 'name-5', 'name-3'
+                ],
+                'message' => 'variation-2',
+            ],
+            [
+                'arrayData' => [
+                    'name-1' => [ // 3
+                        'after' => 'name-6',
+                        'processor' => new \stdClass()
+                    ],
+                    'name-3' => [ // 6
+                        'after' => 'name-5',
+                        'processor' => new \stdClass()
+                    ],
+                    'name-4' => [ // 4
+                        'after' => 'name-1',
+                        'processor' => new \stdClass()
+                    ],
+                    'name-5' => [ // 5
+                        'after' => 'name-4',
+                        'processor' => new \stdClass()
+                    ],
+                    'name-6' => [ // 2
+                        'after' => 'name-2',
+                        'processor' => new \stdClass()
+                    ],
+                    'name-2' => [ // 1
+                        'processor' => new \stdClass()
+                    ],
+                ],
+                'expected' => [
+                    'name-2', 'name-6', 'name-1', 'name-4', 'name-5', 'name-3'
+                ],
+                'message' => 'variation-3',
+            ],
+            [
+                'arrayData' => [
+                    'name-1' => [ // 3
+                        'after' => 'name-6',
+                        'processor' => new \stdClass()
+                    ],
+                    'name-2' => [ // 1
+                        'processor' => new \stdClass()
+                    ],
+                    'name-3' => [ // 6
+                        'after' => 'name-5',
+                        'processor' => new \stdClass()
+                    ],
+                    'name-4' => [ // 4
+                        'after' => 'name-1',
+                        'processor' => new \stdClass()
+                    ],
+                    'name-5' => [ // 5
+                        'after' => 'name-4',
+                        'processor' => new \stdClass()
+                    ],
+                    'name-6' => [ // 2
+                        'after' => 'name-2',
+                        'processor' => new \stdClass()
+                    ],
+                    'name-7' => [ // end
+                        'processor' => new \stdClass()
+                    ],
+                    'name-8' => [ // end
+                        'processor' => new \stdClass()
+                    ],
+                ],
+                'expected' => [
+                    'name-2', 'name-6', 'name-1', 'name-4', 'name-5', 'name-3', 'name-7', 'name-8'
+                ],
+                'message' => 'variation-4',
+            ],
+            [
+                'arrayData' => [
+                    'name-1' => [ // xxx
+                        'after' => 'name-6',
+                        'processor' => new \stdClass()
+                    ],
+                    'name-2' => [ // 1
+                        'processor' => new \stdClass()
+                    ],
+                    'name-3' => [ // xxx
+                        'after' => 'name-XXX',
+                        'processor' => new \stdClass()
+                    ]
+                ],
+                'expected' => ['name-2'],
+                'message' => 'variation-5',
+            ],
+            [
+                'arrayData' => [
+                    'name-1' => [ // xxx
+                        'after' => 'name-3',
+                        'processor' => new \stdClass()
+                    ],
+                    'name-2' => [ // xxx
+                        'after' => 'name-1',
+                        'processor' => new \stdClass()
+                    ],
+                    'name-3' => [ // xxx
+                        'after' => 'name-2',
+                        'processor' => new \stdClass()
+                    ]
+                ],
+                'expected' => [],
+                'message' => 'variation-6',
+            ],
+        ];
+    }
+}
diff --git a/lib/internal/Magento/Framework/View/Test/Unit/Asset/PreProcessor/PoolTest.php b/lib/internal/Magento/Framework/View/Test/Unit/Asset/PreProcessor/PoolTest.php
index eb41418aaefed37555ce5aa5b0114b19dc8a8a23..d7fd211ef79493d7728f4f208a1c4b405dcf4bde 100644
--- a/lib/internal/Magento/Framework/View/Test/Unit/Asset/PreProcessor/PoolTest.php
+++ b/lib/internal/Magento/Framework/View/Test/Unit/Asset/PreProcessor/PoolTest.php
@@ -6,127 +6,181 @@
 
 namespace Magento\Framework\View\Test\Unit\Asset\PreProcessor;
 
-use \Magento\Framework\View\Asset\PreProcessor\Pool;
+use Magento\Framework\ObjectManagerInterface;
+use Magento\Framework\View\Asset\PreProcessor\Pool;
+use Magento\Framework\View\Asset\PreProcessor\Chain;
+use Magento\Framework\View\Asset\PreProcessorInterface;
+use Magento\Framework\View\Asset\PreProcessor\Helper\SortInterface;
 
+/**
+ * Class PoolTest
+ *
+ * @see \Magento\Framework\View\Asset\PreProcessor\Pool
+ */
 class PoolTest extends \PHPUnit_Framework_TestCase
 {
+    const DEFAULT_PREPROCESSOR = 'defaul/preprocessor';
+
+    const CONTENT_TYPE = 'test-type';
+
+    const PREPROCESSOR_CLASS = 'Magento\Framework\View\Asset\PreProcessorInterface';
+
     /**
-     * @var \Magento\Framework\View\Asset\PreProcessor\Pool
+     * @var ObjectManagerInterface|\PHPUnit_Framework_MockObject_MockObject
      */
-    protected $processorPool;
+    private $objectManagerMock;
 
     /**
-     * @var \Magento\Framework\ObjectManagerInterface|\PHPUnit_Framework_MockObject_MockObject
+     * @var SortInterface|\PHPUnit_Framework_MockObject_MockObject
      */
-    protected $objectManager;
+    private $sorterMock;
 
     /**
-     * @var \Magento\Framework\View\Asset\PreProcessor\Chain|\PHPUnit_Framework_MockObject_MockObject
+     * Set up
+     *
+     * @return void
      */
-    protected $processorChain;
-
-    protected function setUp()
+    public function setUp()
     {
-        $this->objectManager = $this->getMockForAbstractClass('Magento\Framework\ObjectManagerInterface');
+        $this->objectManagerMock = $this->getMockBuilder('Magento\Framework\ObjectManagerInterface')
+            ->getMockForAbstractClass();
+        $this->sorterMock = $this->getMockBuilder('Magento\Framework\View\Asset\PreProcessor\Helper\SortInterface')
+            ->getMockForAbstractClass();
+    }
 
-        $this->processorChain = $this->getMockBuilder('Magento\Framework\View\Asset\PreProcessor\Chain')
+    /**
+     * @return Chain|\PHPUnit_Framework_MockObject_MockObject
+     */
+    private function getChainMock($type)
+    {
+        /** @var Chain|\PHPUnit_Framework_MockObject_MockObject $chainMock */
+        $chainMock = $this->getMockBuilder('Magento\Framework\View\Asset\PreProcessor\Chain')
             ->disableOriginalConstructor()
-            ->setMethods([])
             ->getMock();
 
-        $this->processorPool = new Pool(
-            $this->objectManager,
-            [
-                'less' => [
-                    'css' =>
-                        [
-                            'Magento\Framework\Css\PreProcessor\Less',
-                            'Magento\Framework\View\Asset\PreProcessor\VariableNotation',
-                            'Magento\Framework\View\Asset\PreProcessor\ModuleNotation',
-                        ],
-                    'less' =>
-                        [
-                            'Magento\Framework\Css\PreProcessor\Instruction\MagentoImport',
-                            'Magento\Framework\Css\PreProcessor\Instruction\Import',
-                        ],
-                ],
-                'css' => [
-                    'css' => [
-                        'Magento\Framework\View\Asset\PreProcessor\VariableNotation',
-                        'Magento\Framework\View\Asset\PreProcessor\ModuleNotation',
-                    ]
-                ],
+        $chainMock->expects(self::once())
+            ->method('getTargetContentType')
+            ->willReturn($type);
+
+        return $chainMock;
+    }
+
+    /**
+     * @param Chain|\PHPUnit_Framework_MockObject_MockObject $chainMock
+     * @return PreProcessorInterface|\PHPUnit_Framework_MockObject_MockObject
+     */
+    private function getPreprocessorMock($chainMock)
+    {
+        /** @var PreProcessorInterface|\PHPUnit_Framework_MockObject_MockObject $preprocessorMock */
+        $preprocessorMock = $this->getMockBuilder(self::PREPROCESSOR_CLASS)
+            ->getMockForAbstractClass();
+
+        $preprocessorMock->expects(self::once())
+            ->method('process')
+            ->with($chainMock);
+
+        return $preprocessorMock;
+    }
+
+    /**
+     * Run test for process method
+     */
+    public function testProcess()
+    {
+        $preprocessors = [
+            self::CONTENT_TYPE => [
+                'test' => [
+                    Pool::PREPROCESSOR_CLASS => self::PREPROCESSOR_CLASS
+                ]
             ]
+        ];
+
+        $pool = new Pool(
+            $this->objectManagerMock,
+            $this->sorterMock,
+            self::DEFAULT_PREPROCESSOR,
+            $preprocessors
         );
+
+        $this->sorterMock->expects(self::once())
+            ->method('sort')
+            ->with($preprocessors[self::CONTENT_TYPE])
+            ->willReturn($preprocessors[self::CONTENT_TYPE]);
+
+        $chainMock = $this->getChainMock(self::CONTENT_TYPE);
+
+        $this->objectManagerMock->expects(self::once())
+            ->method('get')
+            ->with(self::PREPROCESSOR_CLASS)
+            ->willReturn($this->getPreprocessorMock($chainMock));
+
+        $pool->process($chainMock);
     }
 
     /**
-     * @param string $sourceContentType
-     * @param string $targetContentType
-     * @param array $expectedResult
-     *
-     * @dataProvider getPreProcessorsDataProvider
+     * Run test for process method (default preprocessor)
      */
-    public function testProcess($sourceContentType, $targetContentType, array $expectedResult)
+    public function testProcessDefault()
     {
+        $preprocessors = [
+            'bad-type' => [],
+        ];
 
-        $this->processorChain->expects($this->any())
-            ->method('getOrigContentType')
-            ->willReturn($sourceContentType);
-        $this->processorChain->expects($this->any())
-            ->method('getTargetContentType')
-            ->willReturn($targetContentType);
-        $processorMaps = [];
-        foreach ($expectedResult as $processor) {
-            $processorMock = $this->getMock($processor, ['process'], [], '', false);
-            $processorMock->expects($this->any())
-                ->method('process')
-                ->with($this->processorChain);
-            $processorMaps[] = [$processor, $processorMock];
-        }
-        $this->objectManager
-            ->expects(static::atLeastOnce())
+        $pool = new Pool(
+            $this->objectManagerMock,
+            $this->sorterMock,
+            self::DEFAULT_PREPROCESSOR,
+            $preprocessors
+        );
+
+        $this->sorterMock->expects(self::never())
+            ->method('sort');
+
+        $chainMock = $this->getChainMock(self::CONTENT_TYPE);
+
+        $this->objectManagerMock->expects(self::once())
             ->method('get')
-            ->willReturnMap($processorMaps);
+            ->with(self::DEFAULT_PREPROCESSOR)
+            ->willReturn($this->getPreprocessorMock($chainMock));
 
-        $this->processorPool->process($this->processorChain);
+        $pool->process($chainMock);
     }
 
-    public function getPreProcessorsDataProvider()
+    /**
+     * Run test for process method (exception)
+     *
+     * @expectedException \UnexpectedValueException
+     * @expectedExceptionMessage "stdClass" has to implement the PreProcessorInterface.
+     */
+    public function testProcessBadInterface()
     {
-        return [
-            'css => css' => [
-                'css', 'css',
-                [
-                    'Magento\Framework\View\Asset\PreProcessor\VariableNotation',
-                    'Magento\Framework\View\Asset\PreProcessor\ModuleNotation',
-                ],
-            ],
-            //all undefined types will be processed by Passthrough preprocessor
-            'css => less' => [
-                'css', 'less',
-                ['Magento\Framework\View\Asset\PreProcessor\Passthrough'],
-            ],
-            'less => css' => [
-                'less', 'css',
-                [
-                    'Magento\Framework\Css\PreProcessor\Less',
-                    'Magento\Framework\View\Asset\PreProcessor\VariableNotation',
-                    'Magento\Framework\View\Asset\PreProcessor\ModuleNotation',
-                ],
-            ],
-            'less => less' => [
-                'less', 'less',
-                [
-                    'Magento\Framework\Css\PreProcessor\Instruction\MagentoImport',
-                    'Magento\Framework\Css\PreProcessor\Instruction\Import',
-                ],
-            ],
-            //all undefined types will be processed by Passthrough preprocessor
-            'txt => log (undefined)' => [
-                'txt', 'log',
-                ['Magento\Framework\View\Asset\PreProcessor\Passthrough'],
-            ],
+        $preprocessors = [
+            self::CONTENT_TYPE => [
+                'test' => [
+                    Pool::PREPROCESSOR_CLASS => 'stdClass'
+                ]
+            ]
         ];
+
+        $pool = new Pool(
+            $this->objectManagerMock,
+            $this->sorterMock,
+            self::DEFAULT_PREPROCESSOR,
+            $preprocessors
+        );
+
+        $this->sorterMock->expects(self::once())
+            ->method('sort')
+            ->with($preprocessors[self::CONTENT_TYPE])
+            ->willReturn($preprocessors[self::CONTENT_TYPE]);
+
+        $chainMock = $this->getChainMock(self::CONTENT_TYPE);
+
+        $this->objectManagerMock->expects(self::once())
+            ->method('get')
+            ->with('stdClass')
+            ->willReturn(new \stdClass());
+
+        $pool->process($chainMock);
     }
 }